class PubnubSender():

    def __init__(self, host, port, channel, mybuffer):
        self.consumer = Consumer(host, port, self)
        self.pubnub = Pubnub("pub-c-e655613e-f776-4301-9f29-f71edbcd6559",
                        "sub-c-2eafcf66-c636-11e3-8dcd-02ee2ddab7fe",
                        "sec-c-ZjUwZDgzMTItYzE2Mi00ZGYyLTg2NGMtNmE5N2Q3MGI0MTli",
                        False)
        self.buffer = ((mybuffer == "yes") or (mybuffer == 'y'))
        self.channel = channel

    def run(self):
        while(True):
            self.consumer.waitData()
            data = self.consumer.getData()
            if data is not None:
                time = str(calendar.timegm(
                    datetime.datetime.utcnow().utctimetuple()
                ))
                message = {}
                message['channel'] = self.channel
                if not self.buffer:
                    message['message'] = {}
                    message['message'][time] = data
                else:
                    message['message'] = json.loads(data)
                self.pubnub.publish(message)
class DataConsumerTest():

    def __init__(self, host,port):
        self.consumer = Consumer(host,port, self)

    def run(self):
        while(True):
            self.consumer.waitData()
            data = self.consumer.getData()
            if data != None:
                print str(data)
class FileWriter():

    def __init__(self, host, port, filename):
        self.consumer = Consumer(host, port, self)
        self.filename = filename

    def run(self):
        while(True):
            self.consumer.waitData()
            data = self.consumer.getData()
            if data is not None:
                with open(self.filename, 'a') as the_file:
                    the_file.write(str(data)+'\n')
 def __init__(self, host, port, channel, mybuffer):
     self.consumer = Consumer(host, port, self)
     self.pubnub = Pubnub("pub-c-e655613e-f776-4301-9f29-f71edbcd6559",
                     "sub-c-2eafcf66-c636-11e3-8dcd-02ee2ddab7fe",
                     "sec-c-ZjUwZDgzMTItYzE2Mi00ZGYyLTg2NGMtNmE5N2Q3MGI0MTli",
                     False)
     self.buffer = ((mybuffer == "yes") or (mybuffer == 'y'))
     self.channel = channel
 def __init__(self, host, port, filename):
     self.consumer = Consumer(host, port, self)
     self.filename = filename
 def __init__(self, host,port):
     self.consumer = Consumer(host,port, self)