Tweak channel dates.

This commit is contained in:
Thomas Gideon 2010-09-16 18:11:57 -04:00
parent f2ceb03d0c
commit 2c5014c80f

View file

@ -8,9 +8,7 @@ from BeautifulSoup import BeautifulSoup
def __fetch_feed(url): def __fetch_feed(url):
try: try:
feed = feedparser.parse(url) return feedparser.parse(url)
return feed.entries[0]
except HTTPError, e: except HTTPError, e:
logging.error('Failed with HTTP status code %d' % e.code) logging.error('Failed with HTTP status code %d' % e.code)
return None return None
@ -19,22 +17,28 @@ def __fetch_feed(url):
logging.debug('Network failure reason, %s.' % e.reason) logging.debug('Network failure reason, %s.' % e.reason)
return None return None
def __append(entry, suffix, append_fn, args=None): def __append(feed, suffix, append_fn, args=None):
latest = __fetch_feed('cmdln_%s.xml' % suffix) latest = __fetch_feed('cmdln_%s.xml' % suffix).entries[0]
entry = feed.entries[0]
if entry.title.find(latest.title) != -1: if entry.title.find(latest.title) != -1:
logging.info('Up to date.') logging.info('Up to date.')
return return
f = open('cmdln_%s.xml' % suffix) f = open('cmdln_%s.xml' % suffix)
o = open('cmdln_%s_out.xml' % suffix, 'w') o = open('cmdln_%s_out.xml' % suffix, 'w')
first = False firstItem = False
try: try:
for line in f: for line in f:
if line.find('<item>') != -1 and not first: if line.find('<item>') != -1 and not firstItem:
append_fn(entry, o, suffix, args) append_fn(entry, o, suffix, args)
first = True firstItem = True
if line.startswith(' <pubDate>'):
line = ' <pubDate>%s</pubDate>' % feed.date
if line.startswith(' <lastBuildDate>'):
line = ' <lastBuildDate>%s</lastBuildDate>' % feed.date
o.write(line) o.write(line)
finally: finally:
f.close() f.close()
o.close()
def __append_non_itunes(entry, output, suffix, args): def __append_non_itunes(entry, output, suffix, args):
@ -122,15 +126,15 @@ def __enclosure(enclosures, base_url, suffix):
def main(): def main():
logging.basicConfig(level=logging.INFO, logging.basicConfig(level=logging.INFO,
format='%(message)s') format='%(message)s')
#entry = __fetch_feed('http://thecommandline.net/category/podcast/feed/') #feed = __fetch_feed('http://thecommandline.net/category/podcast/feed/')
entry = __fetch_feed('cmdln_site.xml') feed = __fetch_feed('cmdln_site.xml')
if entry is None: if feed is None:
logging.error('Failed to fetch feed.') logging.error('Failed to fetch feed.')
sys.exit(1) sys.exit(1)
__append(entry, 'mp3', __append_non_itunes) __append(feed, 'mp3', __append_non_itunes)
__append(entry, 'ogg', __append_non_itunes) __append(feed, 'ogg', __append_non_itunes)
__append(entry, 'm4a', __append_itunes, sys.argv) __append(feed, 'm4a', __append_itunes, sys.argv)
if __name__ == "__main__": if __name__ == "__main__":