Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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')
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 def __init__(self, host, port, filename):
     self.consumer = Consumer(host, port, self)
     self.filename = filename
Exemplo n.º 6
0
 def __init__(self, host,port):
     self.consumer = Consumer(host,port, self)