Wed Jan 24 14:16:10 CST 2007

listentoMorningEdition

I usually don't make it to a radio in time to listen to Morning Edition(Sedition). And I got tired of going to the website and clicking the "Listen" button each morning. So I kept track of the url for a few days and put this together. I named it listentoMorningEdition, but I'll likely alias it MorningEdition because that would need two fewer keystrokes for tab completion to resolve.

#!/bin/sh
##################################################
# config options
playerchoice="realplay"
quitchoice="-q "        #set this to "" if you want the player to continue running 
                        #after playing through the show
# initializaion
test="0"
option="1"
##################################################
while [ "$option" = "1" ] ;
do
  option="0"
  if [ "$1" = "-t" ] ; then
    option="1"
    test="1"
    shift
  fi
  if [ "$1" = "-h" ] ; then
    echo "This puts the right date in the url for listening to morning edition,"
    echo "   and plays it in realplay."
    echo ""
    echo "Usage: listentoMorningEdition [-h] [-t]"
    echo "   -h gets this help"
    echo "   -t is a test, shows the command that will be run"
    shift
    exit 1
  fi
done

#need to test the day so as to properly set the prgCode in the url
daytest=`date +%a`
programCode="ME"
if [ "$daytest" = "Sat" ] ; then
        programCode="WESAT"
fi
if [ "$daytest" = "Sun" ] ; then
        programCode="WESUN"
fi

#all the details can now be put into a command string which includes the url
commandstring="$playerchoice $quitchoice\"http://www.npr.org/templates\
/dmg/dmg.php?prgCode="$programCode"&showDate="`date +%d`"-"`date +%b`"\
-"`date +%Y`"&segNum=&NPRMediaPref=RM&getAd=1\" &"

if [ "$test" = "1" ] ; then
  echo "The command string that would be executed:"
  echo $commandstring
  exit 1
fi
##do the job
eval $commandstring

Posted by Phillip | Permalink | Categories: Useful Code