Created
January 15, 2013 09:04
-
-
Save matael/4537364 to your computer and use it in GitHub Desktop.
#jellylemans
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/env python | |
# -*- coding: utf-8 -*- | |
from twitter import Twitter | |
from matplotlib import pyplot | |
twlk = Twitter(domain="search.twitter.com") | |
hashtag = "#jellylemans" | |
res = twlk.search(q=hashtag) | |
users_count = {} | |
users = [] | |
try: | |
while res['next_page']: # genere une key error au besoin | |
for i in res['results']: | |
if i['from_user'] not in users: | |
users.append(i['from_user']) | |
users_count[i['from_user']] = 0 | |
users_count[i['from_user']] += 1 | |
res = twlk.search(q=hashtag, page=res['page']+1) | |
except KeyError: | |
# fail silently if no more page available | |
pass | |
# trim data : compute a mean then suppress all those who are far below | |
count = len(users_count) | |
moy = sum(users_count.values())/count | |
ratio = 1.0 | |
final_count = [] | |
users = [] # re init | |
for i in users_count.keys(): | |
if users_count[i] >= moy*ratio: | |
final_count.append(users_count[i]) | |
users.append(i) | |
pyplot.pie( | |
final_count, | |
labels=users, | |
colors=('b','g', 'r'), | |
labeldistance=1.05 | |
) | |
pyplot.title("Qui a le plus tweete {} ?".format(hashtag)) | |
pyplot.savefig("pie1") | |
print('DONE !') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
c'est quoi le module Twitter utilisé ?