Cobbled together logic for insert a new item in the mp3 feed.

This commit is contained in:
Thomas Gideon 2010-09-16 16:40:55 -04:00
parent 7d55cc49b8
commit 61b59bd4ad
4 changed files with 1997 additions and 4338 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.swp
*out.xml

51
append.py Normal file
View File

@ -0,0 +1,51 @@
import sys
import feedparser
from urllib2 import HTTPError, URLError
import logging
def __fetch_feed(url):
try:
feed = feedparser.parse(url)
return feed.entries[0]
except HTTPError, e:
logging.error('Failed with HTTP status code %d' % e.code)
return None
except URLError, e:
logging.error('Failed to connect with network.')
logging.debug('Network failure reason, %s.' % e.reason)
return None
def __append_mp3(entry):
latest = __fetch_feed('cmdln_mp3_in.xml')
if entry.title.find(latest.title) != -1:
logging.info('Up to date.')
return
f = open('cmdln_mp3_in.xml')
o = open('cmdln_mp3_out.xml', 'w')
first = False
try:
for line in f:
if line.find('<item>') != -1 and not first:
logging.info('Insert new item.')
first = True
else:
logging.info('Preserve existing item.')
o.write(line)
finally:
f.close()
def main():
logging.basicConfig(level=logging.INFO,
format='%(message)s')
entry = __fetch_feed('http://thecommandline.net/category/podcast/feed/')
if entry is None:
logging.error('Failed to fetch feed.')
sys.exit(1)
__append_mp3(entry)
print entry.title
if __name__ == "__main__":
main()

File diff suppressed because it is too large Load Diff

1944
cmdln_site.xml Normal file

File diff suppressed because it is too large Load Diff