From 942a30084e1b7f19d60f4629c4b96f0a08ede8be Mon Sep 17 00:00:00 2001 From: Thomas Gideon Date: Thu, 16 Sep 2010 17:06:00 -0400 Subject: [PATCH] Finished mp3 addition. --- append.py | 72 ++++++++++++++++++++++++++++++++++++++++++++------- cmdln_mp3.xml | 20 +------------- 2 files changed, 63 insertions(+), 29 deletions(-) diff --git a/append.py b/append.py index 11c9580..02ac278 100644 --- a/append.py +++ b/append.py @@ -1,7 +1,9 @@ import sys import feedparser +import urllib2 from urllib2 import HTTPError, URLError import logging +import re def __fetch_feed(url): try: @@ -16,36 +18,86 @@ def __fetch_feed(url): logging.debug('Network failure reason, %s.' % e.reason) return None -def __append_mp3(entry): - latest = __fetch_feed('cmdln_mp3_in.xml') +def __append(entry, suffix, append_fn): + latest = __fetch_feed('cmdln_%s.xml' % suffix) 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') + f = open('cmdln_%s.xml' % suffix) + o = open('cmdln_%s_out.xml' % suffix, 'w') first = False try: for line in f: if line.find('') != -1 and not first: - logging.info('Insert new item.') + append_fn(entry, o) first = True - else: - logging.info('Preserve existing item.') o.write(line) finally: f.close() + +def __append_mp3(entry, output): + (url, mime_type, size) = __enclosure(entry.enclosures, 'http://cmdln.evenflow.nl/mp3', 'mp3') + output.write(""" + %(title)s (Comment Line 240-949-2638) + %(link)s + + %(pubDate)s + + %(permalink)s + +""" % { 'title': entry.title, + 'link': entry.link, + 'description': __description(entry.content), + 'pubDate' : entry.date, + 'permalink' : __permalink(entry.title), + 'url' : url, + 'mime_type' : mime_type, + 'size' : size }) + logging.info('Insert new MP3 item.') + + +def __permalink(title): + permalink = title.lower() + permalink = re.sub('-', '', permalink) + permalink = re.sub('[^a-z0-9]', '-', permalink) + permalink = re.sub('-{2,}', '-', permalink) + if len(permalink) > 48: + permalink = permalink[:48] + return permalink + + +def __description(content): + description = content[0].value + description = re.sub('

\n', '', description) + description = re.sub(re.compile('License.

.*$', re.M | re.S), 'License.

', description) + description = re.sub('

\n', '

\n\n', description) + return re.sub('

View the More news, commentary, and alternate feeds available at http://thecommandline.net/. View the Logo thanks to Jared Axelrod of Free Planet X. - - TCLP 2010-09-15 Interview: Randy Chertkow of Beatnik Turtle (Comment Line 240-949-2638) - http://thecommandline.net/2010/09/15/beatnik_turtle4/ - This is a feature cast, an episode of The Command Line Podcast.

- -

There is no new hacker word of the week this week.

- -

The feature this week is the interview I recorded with Randy Chertkow of Beatnik Turtle. If you are interested, here are the 2007, 2008, and 2009 interviews as well. In the interview, we mention the Indie Guide web site, Randy and Jason's columns at Electronic Musician, and TrackMyDisc.com.

- -

More news and commentary and alternate feeds available at http://thecommandline.net/. View the detailed show notes online. You can grab the flac encoded audio from the Internet Archive.

- -

Creative Commons License

- -

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.

]]> - Wed, 15 Sep 2010 21:30:14 -0400 - - tclp-20100915-interview-randy-chertkow-of-beatn -
TCLP 2010-09-08 Creative Commons, Legal Issue Panel from Dragon*Con 2010 (Comment Line 240-949-2638) http://thecommandline.net/2010/09/08/dragoncon_cc_4/ @@ -4335,4 +4317,4 @@ tclp-20080319-hacking-101-parallel-computing-p - \ No newline at end of file +