As I am unable to read during my morning commute, I have taken to listening to audiobooks to fill the time usefully.
A great source of material to listen to are the shows on BBC Radio 4 Extra. I have a technique for getting the iPlayer content onto my generic mp3 player, but I found trawling through the lists of upcoming programmes to earmark those I wanted to watch rather laborious.
To automate this process, I wanted to get an email on a weekly basis telling me of new upcoming shows. I would then just need to read through the handful of new shows that had been added, as opposed to the entire list. The only computer that I keep on all the time is my Raspberry Pi, so I decided a Python script run using a weekly cron job would meet the case.
I split the problem into 3 basic steps (hence splitting the posts for the project into 3 parts):
- Automatically read all the current shows
- Compare the list of current shows to those of last week
- Send an email of the newly detected shows to me
To accomplish point number 1, I discovered that the main list of shows I browsed regularly (Drama) was available in JSON format by appending .json to the url: http://www.bbc.co.uk/radio4extra/programmes/genres/drama/current.json
Resulting in the raw information about all the current shows. A small sample is below:
{"type":"series","pid":"b01pvbbs","title":"David Constantine - Tea at the Midland","short_synopsis":"Short stories from one of the London Evening Standard's Books of the Year 2012.","image":{"filename":"tea-at-the-midland_midland-hotel-morecambe_140113_s_get.jpg"},"is_available":true},{"type":"series","pid":"b00yjr30","title":"Dick Francis - Dead on Red","short_synopsis":"Simmering resentment brings a high class hit-man over from France to target a jockey","image":{"filename":"dick_francins_dead_on_red_0211_s_get.jpg"},"is_available":true},{"type":"brand","pid":"b01ms5v9","title":"Dickens Confidential","short_synopsis":"Before writing his novels, Charles Dickens worked as editor on a newspaper...","is_available":true}
The next thing to do was to process this using a Python script.
Here is the first test:
#!/usr/bin/python
from urllib import request
import json
url = "http://www.bbc.co.uk/radio4extra/programmes/genres/drama/current.json"
response = request.urlopen(url)
encoding = response.headers.get_content_charset()
json_object = json.loads(response.read().decode('utf-8'))
programmes = json_object['category_slice']['programmes']
for program in programmes:
print (program['title'])
print (program['short_synopsis'])
At this stage, the titles and details of the radio shows are printed on the screen.
I will tackle the use and storage of this data in the next post.
Leave a Reply