Finished mp3 addition.
This commit is contained in:
parent
61b59bd4ad
commit
942a30084e
2 changed files with 63 additions and 29 deletions
72
append.py
72
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('<item>') != -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(""" <item>
|
||||
<title>%(title)s (Comment Line 240-949-2638)</title>
|
||||
<link>%(link)s</link>
|
||||
<description><![CDATA[%(description)s]]></description>
|
||||
<pubDate>%(pubDate)s</pubDate>
|
||||
<enclosure url="%(url)s" length="%(size)s" type="%(mime_type)s"/>
|
||||
<guid isPermaLink="false">%(permalink)s</guid>
|
||||
</item>
|
||||
""" % { '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('<p></p>\n', '', description)
|
||||
description = re.sub(re.compile('License</a>.</p>.*$', re.M | re.S), 'License</a>.</p>', description)
|
||||
description = re.sub('</p>\n', '</p>\n\n', description)
|
||||
return re.sub('<p>View the <a', '<p>More news, commentary, and alternate feeds available at http://thecommandline.net/. View the <a', description)
|
||||
|
||||
|
||||
def __enclosure(enclosures, base_url, suffix):
|
||||
m = re.search('cmdln.net_[0-9]{4}-[0-9]{2}-[0-9]{2}', enclosures[0].href)
|
||||
url = '%s/%s.%s' % (base_url, m.group(), suffix)
|
||||
usock = urllib2.urlopen(url)
|
||||
mime_type = usock.info().type
|
||||
size = usock.info().get('Content-Length')
|
||||
if size is None:
|
||||
size = 0
|
||||
return (url, mime_type, size)
|
||||
|
||||
|
||||
def main():
|
||||
logging.basicConfig(level=logging.INFO,
|
||||
format='%(message)s')
|
||||
entry = __fetch_feed('http://thecommandline.net/category/podcast/feed/')
|
||||
#entry = __fetch_feed('http://thecommandline.net/category/podcast/feed/')
|
||||
entry = __fetch_feed('cmdln_site.xml')
|
||||
if entry is None:
|
||||
logging.error('Failed to fetch feed.')
|
||||
sys.exit(1)
|
||||
|
||||
__append_mp3(entry)
|
||||
__append(entry, 'mp3', __append_mp3)
|
||||
|
||||
print entry.title
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
main()
|
||||
|
|
|
@ -22,24 +22,6 @@
|
|||
<description>Logo thanks to Jared Axelrod of Free Planet X.</description>
|
||||
</image>
|
||||
<atom:link href="http://idisk.me.com/cmdln/Public/cmdln_mp3.xml" rel="self" type="application/rss+xml"/>
|
||||
<item>
|
||||
<title>TCLP 2010-09-15 Interview: Randy Chertkow of Beatnik Turtle (Comment Line 240-949-2638)</title>
|
||||
<link>http://thecommandline.net/2010/09/15/beatnik_turtle4/</link>
|
||||
<description><![CDATA[<p>This is a feature cast, an episode of The Command Line Podcast.</p>
|
||||
|
||||
<p>There is no new hacker word of the week this week.</p>
|
||||
|
||||
<p>The feature this week is the interview I recorded with Randy Chertkow of <a href="http://beatnikturtle.com/">Beatnik Turtle</a>. If you are interested, here are the <a href="http://thecommandline.net/2007/09/05/beatnik_turtle/">2007</a>, <a href="http://thecommandline.net/2008/09/10/beatnik_turtle_2/">2008</a>, and <a href="http://thecommandline.net/2009/09/09/beatnik_turtle3/">2009</a> interviews as well. In the interview, we mention <a href="http://www.indieguide.com/">the Indie Guide web site</a>, <a href="http://emusician.com/searchresults/?ord=d&terms=chertkow&x=0&y=0">Randy and Jason's columns at Electronic Musician</a>, and <a href="http://trackmydisc.com/">TrackMyDisc.com</a>.</p>
|
||||
|
||||
<p>More news and commentary and alternate feeds available at http://thecommandline.net/. View the <a href="http://thecommandline.net/wiki/2010_09_15">detailed show notes online</a>. You can grab the <a href="http://www.archive.org/details/Tclp2010-09-15InterviewRandyChertkowOfBeatnikTurtle">flac encoded audio</a> from the Internet Archive.</p>
|
||||
|
||||
<p><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/us/"><img style="border-width: 0px;" src="http://thecommandline.net/wp-content/uploads/cc-by-sa.png" alt="Creative Commons License" /></a></p>
|
||||
|
||||
<p>This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/us/">Creative Commons Attribution-Share Alike 3.0 United States License</a>.</p>]]></description>
|
||||
<pubDate>Wed, 15 Sep 2010 21:30:14 -0400</pubDate>
|
||||
<enclosure url="http://cmdln.evenflow.nl/mp3/cmdln.net_2010-09-15.mp3" length="56084190" type="audio/mpeg"/>
|
||||
<guid isPermaLink="false">tclp-20100915-interview-randy-chertkow-of-beatn</guid>
|
||||
</item>
|
||||
<item>
|
||||
<title>TCLP 2010-09-08 Creative Commons, Legal Issue Panel from Dragon*Con 2010 (Comment Line 240-949-2638)</title>
|
||||
<link>http://thecommandline.net/2010/09/08/dragoncon_cc_4/</link>
|
||||
|
@ -4335,4 +4317,4 @@
|
|||
<guid isPermaLink="false">tclp-20080319-hacking-101-parallel-computing-p</guid>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
||||
</rss>
|
||||
|
|
Loading…
Reference in a new issue