Script for getting stock quotes (20 minute delay)

Walter Dnes waltdnes-SLHPyeZ9y/tg9hUCZPvPmw at public.gmane.org
Sat Mar 20 04:21:09 UTC 2004


  It's no surprise that a bunch of linux users hang out on Yahoo SCO
stock board, waiting for the ultimate crash & burn.  One has written up
a script to fetch the stock quote for SCO.  He originally hard-coded in
SCOX, but people have substituted ${1}, which allows you to enter any
stock symbol.  It works on a text console.  I call my current version
"q3".  The usage is...

q3 scox
gets SCO

q3 IBM
gets IBM

q3 MSFT
gets microsoft

  Here's what it looks like (markets close at 4:00 PM)

[23:15:54][/misc/home/waltdnes/quotes] ./q3 ibm
Company IBM Date 3/19/2004 Time 4:02pm
Current 91.62 Change -1.23 Volume 7185200
Open 92.86 High 92.97 Low 91.51

  It's more colourfull than that, as you'll see when you run it.  I
don't know if sh supports substrings, so I suggest using /bin/bash in
general.  On many linux distros, sh is a symlink to bash, but it's not
always guaranteed.  The script follows, note one very long line...

#!/bin/bash
#getscox - Free to use and modify!!
# Colors for output
red='\E[31;40m'
green='\E[32;40m'
white='\E[37;40m'
yellow='\E[33;40m'
bold="\033[1m"
normal="\033[0m"

# The following is one long line, it'll wrap on your display
lynx -source "http://finance.yahoo.com/d/quotes.csv?s=${1}&f=sl1d1t1c1ohgv&e=.csv" > stock.csv
# End of long line
ARRAY=(`sed s/[,\"]/\ /g < stock.csv`)
COMPANY=${ARRAY[0]}

SIGN=${ARRAY[4]:0:1}
if [ "$SIGN" = "+" ];
then COLOR=$green
else
COLOR=$red
fi

echo -en $bold"Company" $yellow$COMPANY$normal
echo -en $bold "Date" '\E[33;40m'${ARRAY[2]}$normal
echo -e $bold "Time" $yellow${ARRAY[3]}$normal
echo -en $bold"Current" $yellow${ARRAY[1]}$normal
echo -en $bold "Change"$COLOR ${ARRAY[4]}$normal
echo -e $bold "Volume"$yellow ${ARRAY[8]}$normal
echo -en $bold"Open" $yellow${ARRAY[5]}$normal
echo -en $bold "High" $yellow${ARRAY[6]}$normal
echo -e $bold "Low" $yellow${ARRAY[7]}$normal


tput sgr0

# End of script


-- 
Walter Dnes <waltdnes-SLHPyeZ9y/tg9hUCZPvPmw at public.gmane.org>
Email users are divided into two classes;
1) Those who have effective spam-blocking
2) Those who wish they did
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list