Minor Streaming work; not official, just hackery for fun. Fork and patch or look away.
This commit is contained in:
parent
ed14371d38
commit
2122f6528d
10 changed files with 26 additions and 215 deletions
|
|
@ -1,37 +1,50 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
"""
|
||||
Yes, this is just in __init__ for now, hush.
|
||||
TwythonStreamer is an implementation of the Streaming API for Twython.
|
||||
Pretty self explanatory by reading the code below. It's worth noting
|
||||
that the end user should, ideally, never import this library, but rather
|
||||
this is exposed via a linking method in Twython's core.
|
||||
|
||||
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
|
||||
__author__ = "Ryan McGrath <ryan@venodesigns.net>"
|
||||
__version__ = "1.0.0"
|
||||
|
||||
import urllib
|
||||
import urllib2
|
||||
import urlparse
|
||||
import httplib
|
||||
import httplib2
|
||||
import re
|
||||
|
||||
from urllib2 import HTTPError
|
||||
|
||||
# There are some special setups (like, oh, a Django application) where
|
||||
# simplejson exists behind the scenes anyway. Past Python 2.6, this should
|
||||
# never really cause any problems to begin with.
|
||||
try:
|
||||
import simplejson
|
||||
# Python 2.6 and up
|
||||
import json as simplejson
|
||||
except ImportError:
|
||||
try:
|
||||
import json as simplejson
|
||||
# Python 2.6 and below (2.4/2.5, 2.3 is not guranteed to work with this library to begin with)
|
||||
import simplejson
|
||||
except ImportError:
|
||||
try:
|
||||
# This case gets rarer by the day, but if we need to, we can pull it from Django provided it's there.
|
||||
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 <ryan@venodesigns.net>"
|
||||
__version__ = "0.1"
|
||||
# Seriously wtf is wrong with you if you get this Exception.
|
||||
raise Exception("Twython requires the simplejson library (or Python 2.6) to work. http://www.undefined.org/python/")
|
||||
|
||||
class TwythonStreamingError(Exception):
|
||||
def __init__(self, msg):
|
||||
self.msg = msg
|
||||
|
||||
def __str__(self):
|
||||
return repr(self.msg)
|
||||
return "%s" % str(self.msg)
|
||||
|
||||
feeds = {
|
||||
"firehose": "http://stream.twitter.com/firehose.json",
|
||||
|
|
@ -43,10 +56,5 @@ feeds = {
|
|||
"track": "http://stream.twitter.com/track.json",
|
||||
}
|
||||
|
||||
class stream:
|
||||
class Stream(object):
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue