Skip to content

Instantly share code, notes, and snippets.

@pmuellr
Created January 28, 2011 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmuellr/800617 to your computer and use it in GitHub Desktop.
Save pmuellr/800617 to your computer and use it in GitHub Desktop.
produce a more instapaper-able rollup of RedMonk blogs
#!/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