#!/bin/bash # read in the config file test -r ~/.bartrc && source ~/.bartrc # set some defaults BARTSTART=${BARTSTART:-ROCKR} BARTDEST=${BARTDEST:-EMBAR} FORMAT=${FORMAT:-new} URL_ONLY=0 date_now=$(date +"&time_mode=departs&depart_month=%m&depart_date=%d&depart_time=%I:%M+%p") date_return="" return_delay=0 function pommy { test -x /usr/games/pom && pom | grep -qi 'is full' && echo 'Full moon tonight. Watch out!' test -x /usr/games/pom && pom | grep -qi 'is new' && echo 'Be careful--new moon tonight.' } function usage { echo -e "Usage:\n $(basename $0) [-hondrul] \n $(basename $0) [-hondrul] \n To change defaults, set the BARTSTART and BARTDEST variables in your ~/.bartrc\n" echo "Flags:" echo -e " -o, --old\n\tUse old format (especially if color format isn't working).\n\tAlso FORMAT=old in ~/.bartrc" echo -e " -n, --new\n\tForce use of new format. Also FORMAT=new in ~/.bartrc" echo -e " -d , --delay \n\tUse date hours in the future for departure time." echo -e " -r , --return-delay \n\tUse date hours in the future for return trip time." echo -e " -u, --url\n\tJust print a URL to a schedule suitable for printing." echo -e " -l, --list\n\tList all available station codes and names." echo -e " -h, --help\n\tDisplay this text and exit." } function liststations { wget -O - -o /dev/null 'http://bart.gov/index.asp?ct=1' | html2 2> /dev/null | sed '/\/html\/body\/table\/tbody\/tr\/td\/table\/tr\/td\/form\/select\/@name=origin/,/\/html\/body\/table\/tbody\/tr\/td\/table\/tr\/td\/form\/br/p;d;' | cut -d = -f 2 | grep -v ^/ | tail -n +6 | while read i; do read j; echo -e "$i\t$j"; read blank; done } NORMALCOLOR='\e[0m' NOTECOLOR='\e[0m' TRAINCOLOR='\e[1;31m' TIMECOLOR='\e[1;33m' FARECOLOR='\e[1;32m' BOARDCOLOR='\e[1;36m' STATIONCOLOR='\e[0;36m' function colorformat { while read i do case $i in \$*) echo -e "Current time:\t${TIMECOLOR}$(date +'%l:%M%p')${NORMALCOLOR} (note that first train listed may be in the past)\n${FARECOLOR}$i"; board="Board:";; *train) train=$i; departure=$arrival; beginning=$destination;; at\ *) arrival=${i#at };; Timed|Transfer) read junk; board="Xfer:";; *\ Allowed) echo -e "${BOARDCOLOR}${board}\t${TIMECOLOR}${departure} ${STATIONCOLOR}${beginning} ${NORMALCOLOR}to ${STATIONCOLOR}${destination} ${TIMECOLOR}${arrival} ${TRAINCOLOR}[${train}] ${NOTECOLOR}(${i% Allowed})"; board="\nBoard:";; *) destination=$i;; esac done } function nexttrains { URL="http://bart.gov/textonly/stations/quickplanner/schedule.asp?ct=1&format=quick&origin=${BARTSTART}&destination=${BARTDEST}&print=yes${date_now}${date_return}" if [ "$DUMPBART" = "yes" ]; then wget -O - -o /dev/null ${URL} | html2 2> /dev/null; fi if [ $FORMAT = "new" ] then wget -O - -o /dev/null ${URL} | html2 2> /dev/null | grep -e '\(/html/body/div/div= \$\|/html/body/div/table/tr/td=\)' | cut -d = -f 2 | colorformat else wget -O - -o /dev/null ${URL} | html2text -style compact -nobs | sed '/^Your Schedule/,/^<