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 for k in ('published', 'created', 'updated'):
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)
52 for username in sys.argv[1:]:
53 weeks = log.setdefault(username, [])
54 for l in users[username]['links']:
55 parse_feeds(weeks, l[2])
57 for (username, u) in users.items():
58 weeks = log.setdefault(username, [])
60 parse_feeds(weeks, l[2])
62 with open('out/report.yml', 'w') as f:
63 yaml.safe_dump(log, f)