Created
January 28, 2011 17:39
-
-
Save pmuellr/800617 to your computer and use it in GitHub Desktop.
produce a more instapaper-able rollup of RedMonk blogs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding=utf-8 | |
import sys | |
import time | |
import feedparser | |
feeds = [ | |
[u"Michael Coté", u"http://www.redmonk.com/cote/", u"http://feeds.feedburner.com/PeopleOverProcess"], | |
[u"Tom Raftery", u"http://greenmonk.net/", u"http://greenmonk.net/feed/"], | |
[u"James Governor", u"http://www.redmonk.com/jgovernor/", u"http://feeds.feedburner.com/JamesGovernorsMonkchips"], | |
[u"Stephen O'Grady", u"http://redmonk.com/sogrady/", u"http://redmonk.com/sogrady/feed/"], | |
] | |
#--------------------------------------------------------------------- | |
def main(): | |
entries = [] | |
for feed in feeds: | |
name = feed[0] | |
homeURL = feed[1] | |
feedURL = feed[2] | |
err(u"processing %s's feed: %s" % (name, feedURL)) | |
d = feedparser.parse(feedURL) | |
for entry in d.entries: | |
entries.append(entry) | |
entry.author = name | |
entries.sort(cmp=compareEntryByDate) | |
out('<html>') | |
out('<head>') | |
out('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>') | |
out('<title>RedMonk Weekly</title>') | |
out('</head>') | |
out('<body>') | |
out('<h1>RedMonk Weekly</h1>') | |
for entry in entries: | |
out("") | |
out(u"<hr>") | |
out(u"<h2>%s</h2>" % (entry.title)) | |
out(u"<p>from %s on %s - [<a href='%s'>original entry</a>]" % (entry.author, fdate(entry.date_parsed), entry.link)) | |
out(entry.content[0].value) | |
out("") | |
out('</body>') | |
out('</html>') | |
#--------------------------------------------------------------------- | |
def compareEntryByDate(e1, e2): | |
t1 = time.mktime(e1.date_parsed) | |
t2 = time.mktime(e2.date_parsed) | |
return cmp(t2, t1) | |
#--------------------------------------------------------------------- | |
def fdate(struct_time): | |
return time.strftime("%Y/%m/%d", struct_time) | |
#--------------------------------------------------------------------- | |
def out(string): | |
print string.encode("utf-8") | |
#--------------------------------------------------------------------- | |
def err(string): | |
print >>sys.stderr, string.encode("utf-8") | |
#--------------------------------------------------------------------- | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment