Skip to content

Instantly share code, notes, and snippets.

@abelsonlive
Last active December 29, 2015 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abelsonlive/7653170 to your computer and use it in GitHub Desktop.
Save abelsonlive/7653170 to your computer and use it in GitHub Desktop.
listen to the chat.meatspac.es socket
#!/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