Skip to content

Instantly share code, notes, and snippets.

@hj91
Created June 25, 2011 10:49
Show Gist options
  • Save hj91/1046366 to your computer and use it in GitHub Desktop.
Save hj91/1046366 to your computer and use it in GitHub Desktop.
Example of using Twitter api with Tweepy library
#!/usr/bin/env python
#(c) Harshad Joshi, 2011
#firewalrus [AT] gmail DOT com
import sys
import tweepy
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
ACCESS_KEY = ''
ACCESS_SECRET = ''
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
def start():
a = raw_input ("\n Enter mentions or home or exit to quit :")
if (a == "exit"):
sys.exit(0)
if (a == 'mentions'):
mymentions = api.mentions()
for tweet in mymentions:
d = str(unicode(tweet.text).encode("utf-8"))+" >> "+str(unicode(tweet.user.screen_name).encode("utf-8"))
print d
else:
if (a.lower() == 'home'):
home = api.home_timeline()
for i in home:
print i.text + " >> " + i.user.screen_name
else:
api.update_status(a)
while(1):
start()
@nadia2012
Copy link

•if i want to (Show all the mentions in the user timeline with a count of how many times each one occurred. )
how can i do it ?

@hj91
Copy link
Author

hj91 commented Apr 14, 2012

@nadia2012

you want to see the frequency of how many times your handle is mentioned by a particular user?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment