From 46c93f4adb5f76d60aed3a5ec727ae3f1c548b35 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Mon, 5 Oct 2009 02:07:03 -0400 Subject: [PATCH] A stub for further work on Streaming API integration - nothing to see here yet, move along... --- streaming.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 streaming.py diff --git a/streaming.py b/streaming.py new file mode 100644 index 0000000..b681145 --- /dev/null +++ b/streaming.py @@ -0,0 +1,50 @@ +#!/usr/bin/python + +""" + The beginnings of Twitter Streaming API support in Twython. Don't expect this to work at all, + consider it a stub for now. -- Ryan + + Questions, comments? ryan@venodesigns.net +""" + +import httplib, urllib, urllib2, mimetypes, mimetools, socket, time + +from urllib2 import HTTPError + +try: + import simplejson +except ImportError: + try: + import json as simplejson + except ImportError: + try: + from django.utils import simplejson + except: + raise Exception("Twython (Streaming) requires the simplejson library (or Python 2.6) to work. http://www.undefined.org/python/") + +__author__ = "Ryan McGrath " +__version__ = "0.1" + +class TwythonStreamingError(Exception): + def __init__(self, msg): + self.msg = msg + def __str__(self): + return repr(self.msg) + +feeds = { + "firehose": "http://stream.twitter.com/firehose.json", + "gardenhose": "http://stream.twitter.com/gardenhose.json", + "spritzer": "http://stream.twitter.com/spritzer.json", + "birddog": "http://stream.twitter.com/birddog.json", + "shadow": "http://stream.twitter.com/shadow.json", + "follow": "http://stream.twitter.com/follow.json", + "track": "http://stream.twitter.com/track.json", +} + +class stream: + def __init__(self, username = None, password = None, feed = "spritzer", user_agent = "Twython Streaming"): + self.username = username + self.password = password + self.feed = feeds[feed] + self.user_agent = user_agent + self.connection_open = False