Skip to content

Instantly share code, notes, and snippets.

@ntsh
Created August 2, 2012 19:31
Show Gist options
  • Select an option

  • Save ntsh/3239953 to your computer and use it in GitHub Desktop.

Select an option

Save ntsh/3239953 to your computer and use it in GitHub Desktop.
Twitter favorites of a user through command line
'''
Usage:
> python twit_faves_cli.py username
'''
import httplib
import urllib
import json
import sys
base_url = 'api.twitter.com'
conn = httplib.HTTPConnection(base_url)
def faves(user):
conn.request("GET","/1/favorites/" + user + ".json")
tweets = conn.getresponse().read()
return tweets
def display(tweets):
tweets = json.loads(tweets)
size = len(tweets)
for i in range(0,size):
print "* \"" + tweets[i]['text'] + "\" ~ @" + tweets[i]['user']['screen_name']
print ""
user = sys.argv[1]
print "-----Favorites of user @" + user
tweets = faves(user)
display(tweets)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment