-
-
Save anonymous/11d297e5d1db5b312a2f to your computer and use it in GitHub Desktop.
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
import collections | |
import pygal | |
import requests | |
import sys | |
from bs4 import BeautifulSoup | |
from dateutil import parser | |
user = sys.argv[1] | |
all_datetimes = [] | |
days_of_the_week = ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche'] | |
next_page = "users/%s/comments" % user | |
while next_page: | |
req = requests.get("http://linuxfr.org/%s" % next_page) | |
soup = BeautifulSoup(req.text) | |
for time in soup.find_all('time', class_='updated'): | |
all_datetimes.append(parser.parse(time['datetime'])) | |
next_ = soup.find('a', rel='next') | |
if next_: | |
next_page = next_['href'] | |
else: | |
next_page = None | |
stats = collections.defaultdict(lambda: collections.defaultdict(int)) | |
for dt in all_datetimes: | |
stats[dt.weekday()][dt.hour] += 1 | |
dot_chart = pygal.Dot(x_label_rotation=0) | |
dot_chart.title = '%s Punchcard' % user | |
dot_chart.x_labels = map(str, range(24)) | |
for day in range(len(days_of_the_week)): | |
by_hour = [] | |
for hour in xrange(24): | |
by_hour.append(stats[day][hour]) | |
dot_chart.add(days_of_the_week[day], by_hour) | |
dot_chart.render_to_file("%s_punchcard.svg" % user) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment