]> projects.mako.cc - iron-blogger/commitdiff
Initial reporting script
authorNelson Elhage <nelhage@mit.edu>
Mon, 28 Dec 2009 23:09:11 +0000 (18:09 -0500)
committerNelson Elhage <nelhage@mit.edu>
Mon, 28 Dec 2009 23:09:11 +0000 (18:09 -0500)
report.py [new file with mode: 0644]

diff --git a/report.py b/report.py
new file mode 100644 (file)
index 0000000..3959889
--- /dev/null
+++ b/report.py
@@ -0,0 +1,53 @@
+import yaml
+import feedparser
+import datetime
+from dateutil.parser import parse
+import dateutil.tz as tz
+
+with open('bloggers.yml') as f:
+    users = yaml.safe_load(f.read())
+
+log = {}
+
+START = datetime.datetime(2009, 12, 21, 6)
+
+def parse_published(pub):
+    return parse(pub).astimezone(tz.tzlocal()).replace(tzinfo=None)
+
+def get_date(post):
+    if 'published' in post:
+        return post.published
+    return post.updated
+
+def get_link(post):
+    if 'href' in post:
+        return post.href
+    return post.links[0]['href']
+
+def parse_feeds(weeks, uri):
+    feed = feedparser.parse(uri)
+    for post in feed.entries:
+        date = parse_published(get_date(post))
+
+        if date < START:
+            continue
+        wn = (date - START).days / 7
+
+        while len(weeks) <= wn:
+            weeks.append([])
+        weeks[wn].append(dict(
+                date=date,
+                title=post.title,
+                url=get_link(post)))
+
+for (username, u) in users.items():
+    weeks = []
+    print "[%s]" % (username)
+    for l in u['links']:
+        parse_feeds(weeks, l[2])
+    log[username] = weeks
+    for (i, w) in enumerate(weeks):
+        print " [%d]: %s" % (i, w)
+
+with open('report.yml', 'w') as f:
+    yaml.safe_dump(log, f)

Benjamin Mako Hill || Want to submit a patch?