From e48a880c6d8086ddf161931d0d5040379e0f34ee Mon Sep 17 00:00:00 2001 From: Josh Roesslein Date: Fri, 7 Aug 2009 23:42:30 -0500 Subject: [PATCH] Added status parsing into streaming api. --- stream_watcher.py | 11 ++++++----- tweepy/streaming.py | 13 +++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/stream_watcher.py b/stream_watcher.py index 949c90a..b6bce34 100644 --- a/stream_watcher.py +++ b/stream_watcher.py @@ -1,14 +1,15 @@ 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: diff --git a/tweepy/streaming.py b/tweepy/streaming.py index afa8cab..0cd035d 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -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 -- 2.25.1