getting stock data from yahoo finance
seaside's script; reads 4 char symbols
Code: Select all
#!/bin/sh
#!/bin/bash
# stock ticker- seaside February 6, 2012
# yad version 16.2 required
# stock retrieval ideas from technosaurus
symlist="/root/quotepage"
PIPE=/tmp/stockpipe
mkfifo $PIPE
exec 3<> $PIPE
trap on_exit EXIT
function on_exit () {
echo "quit" >&3
rm -f $PIPE
}
export -f on_exit
yad --notification --kill-parent --listen \
--image=gtk-stop --text="Stock Ticker" \
--command="geany $symlist" <&3 &
# set sample stock info
[[ ! -f $symlist ]] && echo 'ibm
dis
goog ' >$symlist
LINE=1
while true; do
STK=`sed -n "${LINE}p" $symlist`
[ "$STK" = "" ] && LINE=1 && STK=`sed -n "${LINE}p" $symlist` #ran out of lines
QUOTE=`wget -q -O - "http://download.finance.yahoo.com/d/quotes.csv?f=sb3c1&s=$STK"`
#returns "IBM",180.27,-1.77
oldIFS=$IFS
IFS=","
read STOCK BID CHANGE<<<"$QUOTE"
IFS=$oldIFS
STOCK="${STOCK//\"/}"
STOCK="${STOCK:0:4}"
BID="${BID:0:5}"
case $CHANGE in
-*) BG=#FF6F55 ;; #light red
+*) BG=#90EE90 ;; #light green
*) BG=#C7E7F1 ;; #light blue
esac
# technosaurus' use of svg for icons
echo '<svg>
<rect width="64" height="64" x="0" y="0"
style="fill:'"$BG"'"/>
<text x="0.79569316" y="22"
style="font-size:22px"
>'"$STOCK"'</text>
<text x="1" y="48"
style="font-size:22px;font-weight:bold"
>'"$BID"'</text>
</svg> ' >/tmp/stockicon.svg
echo icon:/tmp/stockicon.svg >$PIPE # send notice to change icon
LINE=$[LINE+1]
sleep 3
# Wait before checking again.
done
Last edited by jpeps on Tue 07 Feb 2012, 16:49, edited 1 time in total.
jpeps,jpeps wrote:seaside's script; reads 4 char symbols
Great! I don't know how you squeezed that extra char out by increasing the bottom price pixel to 22. It is counter-intuitive and absolutely beyond me.
Anyway, no one should have any excuses for losing money on the stock market, given these tools.
Regards,
s
The icon size appears to be fixed, so increasing the rect ht, width numbers scales the font size smaller. When I don't understand something, trial & error often works wonders!seaside wrote:jpeps,jpeps wrote:seaside's script; reads 4 char symbols
Great! I don't know how you squeezed that extra char out by increasing the bottom price pixel to 22. It is counter-intuitive and absolutely beyond me.
Anyway, no one should have any excuses for losing money on the stock market, given these tools.
Regards,
s