#!/bin/bash # # Copyright (c) 2002, Brian St. Pierre # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose, without fee, and without a written agreement # is hereby granted, provided that the above copyright notice and this # paragraph and the following two paragraphs appear in all copies. # # IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, # INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST # PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, # EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A # PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" # BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # # $Log: quote,v $ # Revision 1.3 2002/03/14 13:46:25 bstpierre # Yanked CRs # # Revision 1.2 2002/03/14 13:43:46 bstpierre # Added Yahoo as a quote source. # # # function refresh() { wget -q "$1" -O $2 if [ $? != 0 ] then echo wget failed fi } function fetch_nasdaq() { TICKER=$1 CACHEFILE=$HOME/.quotecache/$TICKER.xml URL='http://quotes.nasdaq.com/quote.dll?page=xml&mode=stock&symbol='$TICKER TIMESTAMP=$HOME/.quotecache/TIMESTAMP.nasd HH=`date +"%H"` MM=`date +"%M"` MM=`expr $MM - 5` if [ $MM -lt 0 ] then MM=`expr $MM + 60` fi touch --date="$HH:$MM" $TIMESTAMP if ! [ -f $CACHEFILE ] then refresh $URL $CACHEFILE fi if [ $CACHEFILE -ot $TIMESTAMP ] then refresh $URL $CACHEFILE fi case $2 in last) field='last-sale-price' ;; change) field='net-change-price' ;; vol) field='share-volume-qty' ;; *) exit 1 ;; esac sed " /^#^# s##^# " < $CACHEFILE | cut -d^ -f2,4 } function fetch_yahoo() { TICKER=$1 CACHEFILE=$HOME/.quotecache/$TICKER.csv URL='http://finance.yahoo.com/d/quotes.csv?s='$TICKER'&f=sl1d1t1c1ohgv&e=.csv' TIMESTAMP=$HOME/.quotecache/TIMESTAMP.yahoo HH=`date +"%H"` MM=`date +"%M"` MM=`expr $MM - 5` if [ $MM -lt 0 ] then MM=`expr $MM + 60` fi touch --date="$HH:$MM" $TIMESTAMP if ! [ -f $CACHEFILE ] then refresh $URL $CACHEFILE fi if [ $CACHEFILE -ot $TIMESTAMP ] then refresh $URL $CACHEFILE fi case $2 in last) field=2 ;; change) exit 1 ;; vol) exit 1 ;; *) exit 1 ;; esac cut -d, -f$field < $CACHEFILE } #fetch_nasdaq $* fetch_yahoo $*