Created
August 2, 2012 19:31
-
-
Save ntsh/3239953 to your computer and use it in GitHub Desktop.
Twitter favorites of a user through command line
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
| ''' | |
| 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