Skip to content

Instantly share code, notes, and snippets.

@matael
Created January 15, 2013 09:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matael/4537364 to your computer and use it in GitHub Desktop.
Save matael/4537364 to your computer and use it in GitHub Desktop.
#jellylemans
#!/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 !')
@jblb
Copy link

jblb commented Jan 15, 2013

c'est quoi le module Twitter utilisé ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment