Last active
December 29, 2015 09:49
-
-
Save abelsonlive/7653170 to your computer and use it in GitHub Desktop.
listen to the chat.meatspac.es socket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
from socketIO_client import SocketIO | |
ADDRESS = "https://chat.meatspac.es" | |
class MeatListener(object): | |
def __init__(self): | |
# connect to socket | |
socketIO = SocketIO(ADDRESS, 443) | |
print "listening to", ADDRESS | |
# issue start message | |
# trigger events | |
socketIO.on('message', self.on_message) | |
# wait forever... | |
socketIO.wait() | |
def on_message(self, *args): | |
# parse response and upsert data | |
try: | |
resp = args[0] | |
data = dict( | |
message = resp['chat']['value']['message'].encode('utf-8'), | |
b64_gif = resp['chat']['value']['media'], | |
fingerprint = resp['chat']['value']['fingerprint'], | |
created = resp['chat']['value']['created'] | |
) | |
print data['message'] | |
except Exception as e: | |
# never fail, because then the connection to the stream will stop | |
print("ERROR: " + e.message + "\n") | |
if __name__ == '__main__': | |
listen_to_meat = MeatListener() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment