Created
August 16, 2009 20:45
-
-
Save laiso/168754 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import urlparse | |
import urllib2 | |
from pit import Pit | |
try: | |
import json | |
except ImportError: | |
import simplejson as json | |
SPRITZER_API_URL = 'http://stream.twitter.com/spritzer.json' | |
SPRITZER_API_HOST = urlparse.urlparse(SPRITZER_API_URL).hostname | |
AUTHORIZATION_RELM = 'Firehose' | |
config = Pit.get('twitter.com', | |
{'require': {'login': 'login name', | |
'password': 'login password',}}) | |
USER = config['login'] | |
PASSWORD = config['password'] | |
def _install_opener(): | |
auth_handler = urllib2.HTTPBasicAuthHandler() | |
auth_handler.add_password( | |
AUTHORIZATION_RELM, | |
SPRITZER_API_HOST, | |
USER, PASSWORD | |
) | |
opener = urllib2.build_opener(auth_handler) | |
urllib2.install_opener(opener) | |
def main(): | |
_install_opener() | |
response = urllib2.urlopen(SPRITZER_API_URL) | |
connection = True | |
while (connection): | |
try: | |
next = response.next() | |
status = json.loads(next) | |
if 'text' in status: | |
print "%s: %s" % ( | |
status['user']['screen_name'], | |
status['text']) | |
except Exception, e: | |
connection = False | |
print e | |
print "...close connection." | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment