Skip to content

Instantly share code, notes, and snippets.

@story645
Created August 14, 2014 05:36
Show Gist options
  • Select an option

  • Save story645/43e172f9f65c777b17a9 to your computer and use it in GitHub Desktop.

Select an option

Save story645/43e172f9f65c777b17a9 to your computer and use it in GitHub Desktop.
import twitter
OAUTH_TOKEN = ""
OAUTH_SECRET = ""
CONSUMER_KEY = ""
CONSUMER_SECRET = ""
twitter_stream = twitter.TwitterStream(
auth=twitter.OAuth(OAUTH_TOKEN, OAUTH_SECRET,
CONSUMER_KEY, CONSUMER_SECRET)
)
iterator = twitter_stream.statuses.sample()
obama = 0
nixon = 0
all_tweets = 0
for tweet in iterator:
if u'text' not in tweet.keys():
continue
text = tweet[u'text'].lower()
if 'obama' in text:
obama +=1
elif 'nixon' in text:
nixon +=1
all_tweets +=1
print "Obama: {} Nixon: {} All: {}".format(obama, nixon, all_tweets)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment