Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions streaming/streamnig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/python
# sample of how to access 1% streamnig twitter api
import json
import os
import yaml
from twitter import Twitter, OAuth, TwitterHTTPError, TwitterStream

tokens = yaml.safe_load(open(os.path.expanduser("~") + "/.trawler/default.yaml"))
ACCESS_TOKEN = tokens['access_token']
ACCESS_SECRET = tokens['access_token_secret']
CONSUMER_KEY = tokens['consumer_key']
CONSUMER_SECRET = tokens['consumer_secret']

oauth = OAuth(ACCESS_TOKEN, ACCESS_SECRET, CONSUMER_KEY, CONSUMER_SECRET)
twitter_stream = TwitterStream(auth=oauth)
iterator = twitter_stream.statuses.sample()
tweet_count = 1000
for tweet in iterator:
tweet_count -= 1
print json.dumps(tweet)
if tweet_count <= 0:
break