Finally earlier this year my Dad entered the 21st Century and began downloading the archers podcast from the BBC website. This was by far the simplest and quickest way. This was until the company my Dad works for banned multimedia content downloading on the company network. The only other connection in the house is dial-up so i promised to develop a work around.
I have written a python script which parses the RSS feed for the archers podcast, extracts the .mp3 links, downloads them to a temporary directory, compresses them into a single zip file which, with the help of a bash scrip, gets uploaded to my University web space for my dad to download every Saturday. The script is shown below, but the reason I blog about this is because for the first time in my linux lifetime, I have written a script to do a task in less time that it would have taken to just do it manually! (hence time to blog)
The only remaining task is to get the script to trigger automatically every Saturday without me having to remember. But Google calendar reminders will suffice for the time being!
import feedparser
import urllib
import os
import zipfile
ARCHERS_XML_URL = "http://downloads.bbc.co.uk/podcasts/radio4/archers/rss.xml"
TEMP_ADDRESS = "/tmp/archers/"
feed = feedparser.parse(ARCHERS_XML_URL)
shows = feed["entries"]
episodes = []
for show in shows:
mp3_url = str(show["links"][0]["href"])
print "Retrieving: "+mp3_url
fname = os.path.basename(mp3_url)
try:
f = urllib.urlretrieve(mp3_url, TEMP_ADDRESS+fname)
episodes.append(TEMP_ADDRESS+fname)
except IOError:
print "Couldn't retrieve file: "+mp3_url
urllib.urlcleanup()
all = zipfile.ZipFile(TEMP_ADDRESS+"archers.zip", 'w')
for file in episodes:
try:
all.write(file)
print "added "+file+" to zip archive archers.zip"
except:
print "Faile to write "+file+" to zip archive archers.zip"
all.close()
all = zipfile.ZipFile(TEMP_ADDRESS+"archers.zip", 'r')
if all.testzip() == None:
print "succesfully wrote episodes to zip file"
else:
print "failure writing episodes to zip file"
all.close()
print "end"
1 comment:
My step dad just uses listen again, or the radio in his phone, but congrats on getting a linux script to work - I expect one that will brew coffee every morning next :P
Post a comment