Skip to content

Instantly share code, notes, and snippets.

@firstspring1845
Last active August 29, 2015 13:59
Show Gist options
  • Save firstspring1845/10536138 to your computer and use it in GitHub Desktop.
Save firstspring1845/10536138 to your computer and use it in GitHub Desktop.
import sys,traceback,json,threading
import twitter,util
class Stream():
def __init__(self):
self.listeners = []
t = threading.Thread(target=self.stream)
t.start()
def __add__(self, listener):
self.listeners.append(listener)
return self
def stream(self):
while True:
try:
print('call')
t = twitter.get(0)
r = t.get('https://userstream.twitter.com/2/user.json',params={'include_followings_activity':'true'},stream=True, timeout=10)
for s in r.iter_lines(1):
j = s.decode()
for l in self.listeners:
try:
l(util.prepare(json.loads(j)))
pass
except:
#traceback.print_exc(file=sys.stdout)
pass
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment