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(2011, 10, 24, 6)
20 def parse_published(pub):
21 return parse(pub).astimezone(tz.tzlocal()).replace(tzinfo=None)
24 for k in ('published', 'created', 'updated'):
31 def parse_feeds(weeks, uri):
32 feed = feedparser.parse(uri)
34 print >>sys.stderr, "Parsing: %s" % uri
37 print >>sys.stderr, "WARN: no entries for ", uri
38 for post in feed.entries:
39 date = parse_published(get_date(post))
43 wn = (date - START).days / 7
45 while len(weeks) <= wn:
48 post = dict(date=date,
51 if post['url'] not in [p['url'] for p in weeks[wn]]:
52 weeks[wn].append(post)
55 for username in sys.argv[1:]:
56 weeks = log.setdefault(username, [])
57 for l in users[username]['links']:
58 parse_feeds(weeks, l[2])
60 for (username, u) in users.items():
61 weeks = log.setdefault(username, [])
63 parse_feeds(weeks, l[2])
65 with open('out/report.yml', 'w') as f:
66 yaml.safe_dump(log, f)