Created
May 25, 2012 09:49
-
-
Save dreikanter/2787033 to your computer and use it in GitHub Desktop.
Parse Gist feed using feedparser and demonstrate Atom data structure #python #feeds
This file contains hidden or 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
import feedparser | |
from time import mktime | |
from datetime import datetime | |
def format_datetime(struct_time): | |
return datetime.fromtimestamp(mktime(struct_time)) | |
def read_gist_feed(github_user): | |
url = "http://gist.github.com/%s.atom" % github_user | |
d = feedparser.parse(url) | |
print "Feed title:", d.feed.title | |
print "Link:", d.feed.link | |
if hasattr(d.feed, 'subtitle'): | |
print "Subtitle:", d.feed.subtitle | |
print "Updated:", d.feed.updated | |
print "Updated (parsed):", format_datetime(d.feed.updated_parsed) | |
print "Feed ID:", d.feed.id | |
print "\nEntries:" | |
for entry in d.entries: | |
print " * Title:", entry.title | |
print " Link: %s", entry.link | |
print " Published: %s", format_datetime(entry.published_parsed) | |
print " Updated: %s", format_datetime(entry.updated_parsed) | |
print " Summary length:", len(entry.summary) | |
print " Content items count:", len(entry.content) | |
read_gist_feed("dreikanter") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment