#!/bin/bash # Sun Mar 21 14:26:22 EST 2004 # NAME: stock # Copyright 2004, Chris F.A. Johnson # Released under the terms of the GNU General Public License version() { echo " $progname, version $version Copyright $copyright, $author $email This is free software, released under the terms of the GNU General Public License. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. " } usage() { echo " $progname - $description USAGE: $progname [OPTIONS] OPTIONS: " [ $longusage -eq 1 ] && echo " -h - help: print shorter help message -H - help: print this message" || echo " -h - help: print this message -H - help: print more detailed message" echo " -v - verbose: -V - print version information " [ $longusage -eq 1 ] && version || echo " Copyright 2004, Chris F.A. Johnson " } description="" verbose=0 longusage=0 version="1.0" copyright=2004 author="Chris F.A. Johnson" progname=${0##*/} stockdir=$HOME/work/stocks [ -d "$stockdir" ] || mkdir -p "$stockdir" while getopts vVhH-: var do case $var in -) case $OPTARG in help) usage; exit ;; help_long) longusage=1; usage; exit ;; version) version; exit ;; esac ;; h) usage; exit ;; H) longusage=1; usage; exit ;; v) verbose=$(( $verbose + 1 )) ;; V) version; exit ;; *);; esac done shift $(( $OPTIND - 1 )) #getscox - Free to use and modify!! commas() { _COMMAS= local left num decimal case $1 in *.*) num=${1%.*} decimal=${1#.} ;; *) num=$1 decimal= ;; esac while : do case $num in ???|??|?) _COMMAS=${num}${_COMMAS:+,$_COMMAS}; break ;; *) left=${num%???} _COMMAS=${num#${left}}${_COMMAS:+,$_COMMAS} num=$left ;; esac done _COMMAS=${_COMMAS}${decimal:+.$decimal} } split() { local IFS=',' set -- ${1//\"/} [ $# -lt 9 ] && exit 1 company=$1 current=$2 date=$3 time=$4 datestr="$date $time" change=$5 volume=$9 open=$8 high=$7 low=$6 eval `date -d "$datestr" "+y=%Y m=%m d=%d h=%H M=%M S=%S Mmm=%b Day=%a "` } CR=$'\r' # Colors for output red=$'\e[31m' green=$'\e[32;47m' white=$'\e[37;40m' yellow=$'\e[33;40m' bold=$'\e[1m' normal=$'\e[0m' reverse=$'\e[7m' #CO=${1:-SCOX} [ $# = 0 ] && set -- SCOX for CO do source="http://finance.yahoo.com/d/quotes.csv?s=${CO}&f=sl1d1t1c1ohgv&e=.csv" quote=`lynx -source "$source"` [ ${verbose:=0} -ge 1 ] && printf "\t%s\n" ${quote//,/ } split "${quote%$CR}" case $change in -*) COLOR=$red ;; *) COLOR=$green ;; esac hformat="%-8s%-11s%-8s%-8s%-8s%-15s%-8s%-8s%-8s\n" dformat="%-8s%-11s%-8s%-8s${COLOR}%-8s${normal}%-15s%-8s%-8s%-8s\n" fformat="%s,%s,%s,%s,%s,%s,%s,%s,%s\n" printf "$hformat" Company Date Time Current Change Volume Open High Low commas $volume printf "$dformat" ${company} $y-$m-$d ${h}:${M} ${current} ${change} ${_COMMAS} ${open} ${high} ${low} tput sgr0 printf "$fformat" ${company} $y-$m-$d ${h}:${M} ${current} ${change} ${volume} ${open} ${high} ${low} >> "$stockdir/$company" sort -uo "$stockdir/$company" "$stockdir/$company" done