Wednesday, 16 March 2011

Automating BBC News Every Morning

One of my morning routines is to watch the news every morning as I'm having a coffee and getting ready. Usually I'll watch the previous nights 10 o'clock news on iPlayer, this requires me to open up the iPlayer website every morning, scroll down to "BBC News At 10", open this on either the same page or a new page and then play the content




Although this isn't the most labour intensive thing that I've ever had to do, it's just become a bit of a pain to have to do it every morning. So I was wondering if there was a way that I could automate the process.

So there were a couple of things to achieve:

  • Have an automated action to open the iPlayer website at the correct 10 o'clock news site (which will probably change every day as the next day's video is uploaded)
  • Have this action performed at a certain time every day
I first looked at how to set up repeating events. Using iCal seemed to be one option as it can have it's reminders execute scripts - however I have moved away from iCal for a while (in favour of plain old GCal) so i didn't really want to use it.


Instead I found out that Mac OS actually has some form of event timing system built in (as I'm sure every other OS does) called Cron. More information can be found here and I have decided to use this as my scheduling tool. Using the CronniX application to provide a workable GUI for the Cron daemon (I usually like doing this manipulation stuff in Terminal but I wanted to get it done before a meeting so didn't have much time) I then scheduled an event to go off at 8:10 every morning, using the simple schedule tab I could paste the destination of my script file into the "Command" box, in order to execute the script I just needed to tick the "Prepend /usr/bin/open" box (I'm guessing this runs the process that opens files and applications - I look into the inner workings of CronniX later).


Now that I had the ability to schedule my event I just needed to make it. Although at the beginning I said that I wanted to have an AppleScript because I feel that it would have been great to practice my coding, time constraints again dictated that I find a simper solution. So I turned to Automator and built up the simple workflow below that would open the correct webpage.


The workflow works as follows

  1. Obtaining and navigating to the BBC iPlayer homepage in the default browser (chrome)
  2. Displaying the homepage
  3. Searching the homepage for URLs
  4. Filtering these URLs and only keeping the ones that contain the string BBC_News_at_Ten (this is the standard naming convention that is used)
  5. Displaying this webpage

All I then had to do was to save this as an application, point the Cron daemon towards it and let it do its thing!

I understand that I'll obviously have to watch out in terms of this will open every-day, and I'm not sure how it will react to weekends because there is no "News at 10" it's only the "Weekend News". I think the workflow will simply fail and nothing much will happen but I can always schedule this not to happen on a weekend

When I get time I'll change a couple of things, notably I want the whole thing to be run as a script so that I can get some experience in using AppleScript. Also it would be good to close the original iPlayer homepage after opening the news tab and of course I want to look more into the Cron daemon, /usr/bin/open function and other lower level OS stuff. Mostly because I enjoy getting to grips with this stuff but also because there could be certain other things that I could begin to automate!

No comments:

Post a Comment