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

Fri Nov 3 18:50:26 CST 2006

command line wikipedia

A helpful friend and I put this together. It is a little script to access wikipedia from the command line (inspired by dict). I have it saved as "wikip". It is nice and minimal, I usually use -p, but that requires you get the name of a page just right (which can be annoying if someone made the wikipedia page with odd capitalization.

#!/bin/sh
##################################################
# configuration

# set to default browser
browser="lynx -nopause"
##################################################

search="0"
text="0"
extra=""

if [ -z "$1" ] ; then
  echo "What wikipedia entry do you want?"
  echo "Usage: wikip [-s] [-t] [-f] [-o] [-l]  terms..." 1>&2
  echo "   -s search" 1>&2
  echo "   -t dump as text, no interface" 1>&2
  echo "   -f use firefox, not default browser ($browser)" 1>&2
  echo "   -o use opera, not default browser ($browser)" 1>&2
  echo "   -l use lynx, not default browser ($browser)" 1>&2
  echo "   -p use less to paginate, forces dump as text, i.e. no browser" 1>&2
  exit 1
fi

option="1"
while [ "$option" = "1" ] ;
do
  option="0"
  if [ "$1" = "-l" ] ; then
    browser="lynx -nopause"
    option="1"
    shift
  elif [ "$1" = "-s" ] ; then
    search="1"
    option="1"
    shift
  elif [ "$1" = "-t" ] ; then
    text="1"
    option="1"
    shift
  elif [ "$1" = "-o" ] ; then
    browser="opera -newpage"
    option="1"
    shift
  elif [ "$1" = "-f" ] ; then
    browser="firefox"
    option="1"
    shift
  elif [ "$1" = "-p" ] ; then
    extra=" | less"
    text="1"
    option="1"
    shift
  fi
done

term=`echo $*|sed 's/\ /_/g'`

if [ "$search" = "1" ] ; then
  URL="http://en.wikipedia.org/wiki/Special:Search/$term"
else
  URL="http://en.wikipedia.org/wiki/$term"
fi

if [ "$text" = "1" ] ; then
  eval lynx -nopause -nolist -dump \"$URL\" $extra
else
  $browser "$URL" 
fi

Posted by Phillip | Permalink | Categories: Useful Code