From 6fde85012de4ea94f00883c13afcbe47a39372b6 Mon Sep 17 00:00:00 2001 From: Thomas Gideon Date: Fri, 5 Nov 2010 16:53:45 -0400 Subject: [PATCH] Changing feed append code to use an external configuration file. --- .gitignore | 1 + README | 1 + append.py | 60 +++++++++++++++++++++++++++++++--------------------- restore.bash | 12 +++++++++++ 4 files changed, 50 insertions(+), 24 deletions(-) create mode 100755 restore.bash diff --git a/.gitignore b/.gitignore index 6f1cd41..0943b11 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ *.m4a *.chapters.txt *.conf +*.feed diff --git a/README b/README index d80169a..1fea9df 100644 --- a/README +++ b/README @@ -9,3 +9,4 @@ with_offset.xsl - Transform that handles the recursive structure of OmniOutliner without_offset.xsl - Transform that handles the recursive structure of OmniOutliner files better than Beautiful Soup does, works with segment notes that do not have time offsets. outline.bash - Drives the XSLT operation and subsequent scripting tasks that cannot be handled in XSL. cleanup.bash - Remove output files produced from encode.bash +restore.bash - Restore backup of feed files made today on top of current feed files. diff --git a/append.py b/append.py index 294321e..faed2af 100755 --- a/append.py +++ b/append.py @@ -53,13 +53,14 @@ def __fetch_feed(url): return None -def __append(feed, suffix, append_fn): +def __append(config, feed, suffix, append_fn): """ For the given main site feed, load the appropriate media specific feed and compare. If the latest episode isn't in the media specific feed, insert it making the necessary adjustments to the new episode's entry. """ - latest = __fetch_feed('cmdln_%s.xml' % suffix).entries[0] + local_file = '%s%s.xml' % (config['file_prefix'], suffix) + latest = __fetch_feed(local_file).entries[0] entry = feed.entries[0] if latest.title.find(entry.title) != -1: logging.info('%s is up to date.' % suffix) @@ -67,7 +68,7 @@ def __append(feed, suffix, append_fn): entry.title.encode('ascii') base_url = 'http://www.archive.org/download/%s' % __archive_slug(entry.title) - filename = 'cmdln_%s.xml' % suffix + filename = '%s%s.xml' % (config['file_prefix'], suffix) today = datetime.date.today() backup = '%s.%s' % (filename, today.strftime('%Y-%m-%d')) shutil.copy(filename, backup) @@ -78,7 +79,7 @@ def __append(feed, suffix, append_fn): updated = time.strftime('%a, %d %b %Y %X +0000', feed.updated) for line in f: if line.find('') != -1 and not firstItem: - append_fn(entry, o, suffix, base_url) + append_fn(config, entry, o, suffix, base_url) firstItem = True if line.startswith(' '): line = ' %s\n' % updated @@ -90,15 +91,15 @@ def __append(feed, suffix, append_fn): o.close() -def __append_non_itunes(entry, output, suffix, base_url): +def __append_non_itunes(config, entry, output, suffix, base_url): """ For most of the feeds, new episodes are simple stanzas and the adjustments consist mostly of copying what is in the mean site feed's entry and just re-writing the enclosure to the appropriate media file. """ - (url, mime_type, size) = __enclosure(entry.enclosures, base_url, suffix) + (url, mime_type, size) = __enclosure(config, entry.enclosures, base_url, suffix) output.write(""" - %(title)s (Comment Line 240-949-2638) + %(title)s%(title_suffix)s %(link)s %(pubDate)s @@ -107,16 +108,17 @@ def __append_non_itunes(entry, output, suffix, base_url): """ % { 'title': entry.title, 'link': entry.link, - 'description': __description(entry.content), + 'description': __description(config, entry.content), 'pubDate' : entry.date, 'permalink' : __permalink(entry.title), 'url' : url, 'mime_type' : mime_type, - 'size' : size }) + 'size' : size, + 'title_suffix': config['title_suffix'] }) logging.info('Inserted new %s item.' % suffix) -def __append_itunes(entry, output, suffix, base_url): +def __append_itunes(config, entry, output, suffix, base_url): """ For the iTunes/AAC feed, there are some additional elements that make use of the Apple extensions to RSS. Some of these, like the duration, @@ -124,20 +126,20 @@ def __append_itunes(entry, output, suffix, base_url): produced by PodPress is less than desirable so those get munged to something more suitable before writing into the iTunes feed. """ - description = __description(entry.content) + description = __description(config, entry.content) soup = BeautifulSoup(description) summary = '\n\n'.join([''.join(p.findAll(text=True)) for p in soup.findAll('p')]) - (url, mime_type, size) = __enclosure(entry.enclosures, base_url, suffix) + (url, mime_type, size) = __enclosure(config, entry.enclosures, base_url, suffix) if size == 0: raise Exception('Couldn not find media, %s.' % base_url) output.write(""" - %(title)s (Comment Line 240-949-2638) + %(title)s%(title_suffix)s %(link)s %(pubDate)s %(permalink)s - Thomas Gideon + %(author)s %(subtitle)s %(summary)s no @@ -153,7 +155,9 @@ def __append_itunes(entry, output, suffix, base_url): 'size' : size, 'subtitle' : ''.join(soup.contents[0].findAll(text = True)), 'summary' : summary, - 'duration' : entry.itunes_duration }) + 'duration' : entry.itunes_duration, + 'title_suffix': config['title_suffix'], + 'author': config['author'] }) logging.info('Inserted new %s item.' % suffix) @@ -174,7 +178,7 @@ def __permalink(title): return permalink -def __description(content): +def __description(config, content): """ This function strips out parts of the description used in the main site feed that are less appropriate for the media specific feeds. PodPress @@ -191,12 +195,12 @@ def __description(content): return re.sub('

View the More news, commentary, and alternate feeds available at http://thecommandline.net/. View the