5 from dateutil.parser import parse
6 import dateutil.tz as tz
8 with open('bloggers.yml') as f:
9 users = yaml.safe_load(f.read())
13 START = datetime.datetime(2009, 12, 21, 6)
15 def parse_published(pub):
16 return parse(pub).astimezone(tz.tzlocal()).replace(tzinfo=None)
19 if 'published' in post:
25 links = dict((l.rel, l) for l in post.links if 'html' in l.type)
27 return links['self'].href
28 elif 'alternate' in links:
29 return links['alternate'].href
34 def parse_feeds(weeks, uri):
35 feed = feedparser.parse(uri)
36 for post in feed.entries:
37 date = parse_published(get_date(post))
41 wn = (date - START).days / 7
43 while len(weeks) <= wn:
45 weeks[wn].append(dict(
50 for (username, u) in users.items():
52 print "[%s]" % (username)
54 parse_feeds(weeks, l[2])
56 for (i, w) in enumerate(weeks):
57 print " [%d]: %s" % (i, w)
59 with open('out/report.yml', 'w') as f:
60 yaml.safe_dump(log, f)