Commit e48a880c authored by Josh Roesslein's avatar Josh Roesslein
Browse files

Added status parsing into streaming api.

parent 0eede72d
import time
from getpass import getpass
import tweepy
def callback(stream_object):
def callback(status):
if 'text' in stream_object:
print stream_object['text']
print status.text
stream = tweepy.Stream('spritzer', 'tweebly', 'omega1987twitter')
username = raw_input('Twitter username: ')
password = getpass('Twitter password: ')
stream = tweepy.Stream('spritzer', username, password)
stream.connect(callback)
while True:
......
......@@ -6,6 +6,8 @@ import httplib
from threading import Thread
from . auth import BasicAuthHandler
from . parsers import parse_status
from . api import API
try:
import json
......@@ -22,6 +24,7 @@ class Stream(object):
self.buffer_size = buffer_size
def _run(self):
api = API()
conn = httplib.HTTPConnection(self.host)
headers = {}
self.auth.apply_auth(None, None, headers, None)
......@@ -47,8 +50,14 @@ class Stream(object):
# read data
data = resp.read(length)
jobject = json.loads(data)
self.callback(jobject)
# turn json data into status object
if 'in_reply_to_status_id' in data:
status = parse_status(data, api)
self.callback(status)
# TODO: we should probably also parse delete/track messages
# and pass to a callback
conn.close()
self.running = False
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment