Created
June 3, 2011 09:55
-
-
Save nickloman/1006118 to your computer and use it in GitHub Desktop.
Little Tweet ripper
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
## little tweet ripper, run python get.py ABPH11 | |
import operator | |
import sys | |
import urllib | |
import json | |
url = "http://search.twitter.com/search.json" | |
u_hash = {} | |
def page(page, term): | |
last_created_at = None | |
params = urllib.urlencode({'q': term, | |
'rpp' : 100, | |
'page' : page}) | |
f = urllib.urlopen("%s?%s" % (url, params)) | |
print page | |
o = json.load(f) | |
for tweet in o['results']: | |
if tweet['from_user'] in u_hash: | |
u_hash[tweet['from_user']] += 1 | |
else: | |
u_hash[tweet['from_user']] = 1 | |
print "%s: %s" % (tweet['from_user'], tweet['text'].encode('ascii', 'ignore')) | |
last_created_at = tweet['created_at'] | |
return last_created_at | |
def go(term): | |
for n in xrange(1, 15): | |
if not page(n, term): | |
break | |
# for key, val in u_hash.iteritems(): | |
# print key, val | |
authors = sorted(u_hash.iteritems(), key=operator.itemgetter(1)) | |
for a in authors: | |
print a[0], a[1] | |
go(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment