29 Sep 2013 slef   » (Master)

Send updates to live cycling news reports to the speech synth

The BBC coverage of the UCI Women Road Race World Championship wasn’t starting until 3pm, BBC Radio 5 Live had football and Sports Extra was playing an advert loop (really BBC?), Eurosport wasn’t covering the race at all, RAI Sport 2 had coverage which was fine while I was watching the TV, but my Italian isn’t good enough to follow the commentary and I wanted to get some other stuff done.

So the obvious thing is to have the computer watch for changes to the great http://live.cyclingnews.com/ ticker and read them out, right? Well, it was to me. Here’s the script I used:

#!/usr/bin/rc
# Send updates to live cycling news reports to the speech synth

# initialise
url=http://live.cyclingnews.com/
if (~ $1 *:*) {
  url=$1
}
last=""

while (true) {
    # download the update and strip html - if you don't have html2text try
    # sed -e '1,/<ol/d;s/<br[^>]*>/n/g;s/<[^>]*>//g;s/ / /g;s/[[:space:]]*$//'
    next=``(){curl -s $url | html2text -width 9999 | sed -e 's/^ *[0-9]*. //' }
    # look for some added lines in the update section - timezone will need changing for non-European races
    say=``(){diff -u <{echo $last} <{echo $next} 
      | sed -ne '/^+/!d;s///;s/**//g;/ CES*T/,/^ *$/p' | head -9 }
    # feed them to the speech synth in reverse order
    echo $say '
      Race Update' | tac | spd-say -e
    # update variables, pause and loop
    last=$next
    # set this to a prime number over 60, like 61, 67, 71, 73, 79, 83, 89
    sleep 67
}

Any questions, comments or improvements? I could have done more, like not saying “Race Update” even when there was no update, but I wanted to start listening as soon as possible!

Syndicated 2013-09-29 04:28:51 from Software Cooperative News » mjr

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!