Created
November 15, 2010 02:07
-
-
Save jkern/676326 to your computer and use it in GitHub Desktop.
LISA 10 Weigher
This file contains 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
#!/usr/bin/python | |
import urllib2 | |
import json | |
import base64 | |
import operator | |
import math | |
PAGE = 1 | |
BASE_URL='http://search.twitter.com/search.json?q=%23lisa10&rpp=100&until=2010-11-12&page=' | |
username = '' #your username here | |
password = '' #your password here | |
def Linker(username): | |
return '<a href=http://twitter.com/' + username + '>' + username + '</a>' | |
def Cloud(text, size, tweets): | |
return '<span style="font-size: ' + size + 'em">' + text + '</span><sup>'+ str(tweets) +'</sup><br>' | |
def Sizer(tweets): | |
if tweets == 1: | |
return str(1) | |
else: | |
return str(math.ceil(2 * math.log(tweets, math.e))) | |
stop = False | |
twitter_users = { } | |
while not stop: | |
try: | |
request = urllib2.Request( BASE_URL + str(PAGE) ) | |
request.add_header( 'Authorization', 'Basic ' + base64.b64encode( username + ':' + password ) ) | |
response = json.load(urllib2.urlopen( request )) | |
for tweet in response['results']: | |
if str(tweet['from_user']) in twitter_users: | |
twitter_users[str(tweet['from_user'])] += 1 | |
else: | |
twitter_users[str(tweet['from_user'])] = 1 | |
PAGE += 1 | |
except urllib2.HTTPError: | |
stop = True | |
sorted_twitter_users = sorted(twitter_users.iteritems(), key=operator.itemgetter(1)) | |
sorted_twitter_users.reverse() | |
for user in sorted_twitter_users: | |
print Cloud(Linker(user[0]),Sizer(user[1]), user[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't make too much fun. This was a run-once script.