Example #1
0
    def open(self):
        SOCKETS.append(self)
        print "WebSocket opened"

        db = Database()
        messages = db.get_messages(5)

        for msg in messages:
            response = {'user': msg[2], 'action': 'add', 'val': msg[1], 'line': msg[0],
                        'date': str(datetime.datetime.fromtimestamp(msg[3]).strftime("%B %d, %Y")),
                        'online': len(SOCKETS)}

            data = json.dumps(response)
            self.write_message(data)
Example #2
0
 def on_close(self):
     print "WebSocket closed"
     SOCKETS.remove(self)