6 from dateutil.parser import parse
7 import dateutil.tz as tz
9 with open('bloggers.yml') as f:
10 users = yaml.safe_load(f.read())
13 with open('out/report.yml') as f:
14 log = yaml.safe_load(f.read())
18 START = datetime.datetime(2009, 12, 21, 6)
20 def parse_published(pub):
21 return parse(pub).astimezone(tz.tzlocal()).replace(tzinfo=None)
24 if 'published' in post:
31 def parse_feeds(weeks, uri):
32 feed = feedparser.parse(uri)
34 print >>sys.stderr, "WARN: no entries for ", uri
35 for post in feed.entries:
36 date = parse_published(get_date(post))
40 wn = (date - START).days / 7
42 while len(weeks) <= wn:
45 post = dict(date=date,
48 if post['url'] not in [p['url'] for p in weeks[wn]]:
49 weeks[wn].append(post)
51 for (username, u) in users.items():
52 weeks = log.setdefault(username, [])
54 parse_feeds(weeks, l[2])
56 with open('out/report.yml', 'w') as f:
57 yaml.safe_dump(log, f)