getting stock data from yahoo finance

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#46 Post by jpeps »

Cute! Glad it eliminates all those pesky 4 letter stocks, like MSFT.

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#47 Post by jpeps »

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.

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#48 Post by seaside »

jpeps wrote:seaside's script; reads 4 char symbols
jpeps,

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

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#49 Post by jpeps »

seaside wrote:
jpeps wrote:seaside's script; reads 4 char symbols
jpeps,

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
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#50 Post by seaside »

jpeps,

Good find. It just never even occurred to me to change the width height bigger than the tray icon.

Regards,
s
(Of course, the hard part then is to see exactly what the effect is with each change..... maybe a GUI for that :) )

Post Reply