# coding: utf-8

import time
import codecs
import json

from app import stream

class chargen_cl(object):
    exposed = True
    
    chargenCounter = 1
    
    def __init__(self):
        self.stream = stream.stream_cl()
    
    def NEXT(self):        
        if(self.chargenCounter > self.stream.anzChargen()):
            self.chargenCounter = 1
            
#        timeout = 0        
#        while(self.chargenCounter > self.stream.anzChargen()):
#            print(self.stream.anzChargen())
#            time.sleep(1)
#            timeout += 1        
#            if(timeout > 3600):
#                return -1

        newCharge = self.stream.loadCharge(self.chargenCounter)
        self.chargenCounter += 1
        
        return json.dumps(newCharge)
    