Skip to content

Instantly share code, notes, and snippets.

@np1
Last active December 17, 2015 18:09
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 np1/5651109 to your computer and use it in GitHub Desktop.
Save np1/5651109 to your computer and use it in GitHub Desktop.
Parse YouTube channel RSS feed data without additional libraries
#!/usr/bin/python
import urllib2
import time
from xml.etree import ElementTree as etree
class YTFeedParser(list):
def __init__(self, url):
rawfeeddata = urllib2.urlopen(url).read()
tree = etree.fromstring(rawfeeddata)
items = tree.findall('channel/item')
self.items = []
formatstring = "%a, %d %b %Y %H:%M:%S +0000"
for item in items:
d = dict()
for tag in "pubDate title link author".split(" "):
d[tag] = item.find(tag).text
d['parsed_date'] = time.strptime(d['pubDate'], formatstring)
self.append(d)
# example usage
link = ('http://gdata.youtube.com/feeds/base/users/LetsPlay/uploads?alt=rss&v='
'2&orderby=published&client=ytapi-youtube-profile')
feed = YTFeedParser(link)
for feeditem in feed:
for k, v in feeditem.items():
print k, ":", v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment