Skip to content

Instantly share code, notes, and snippets.

@ryanfb
Forked from bkerley/gist:13858
Created September 30, 2008 18:07
Show Gist options
  • Save ryanfb/13898 to your computer and use it in GitHub Desktop.
Save ryanfb/13898 to your computer and use it in GitHub Desktop.
proc stockgetchr html {
if {[llength [regexp -all -inline {<link rel="stylesheet".*mutualfund_styles.css">} $html]] > 0} {
set chrt [regexp -all -line -inline {<span class.?=.?"ch[rg]">\n(.*?)\n(.*?)\n} $html]
lset chrt 1 [regsub -all {&nbsp;} [lindex $chrt 1] ""]
lappend chr [lindex $chrt 1] [lindex $chrt 2]
} else {
set chrt [regexp -all -inline {<span class="ch[rg]".*?>(.*?)<} $html]
lappend chr [lindex $chrt 1] [lindex $chrt 3]
}
return $chr
}
proc stock symbol {
set html [unescape_html_entities [wget http://finance.google.com/finance?q=$symbol]];
set cn [html [strip_html [lindex [regexp -all -inline {<h1>(.*?)</h1>} $html] 1]]];
set curr [html [strip_html [lindex [regexp -all -inline {<span class="pr".*?>(.*?)<} $html] 1]]];
set chr [stockgetchr $html];
if {[lindex $chr 0] < 0} {set col red} else {set col green};
. "[bold]$curr[bold]: [color $col on white][html [strip_html [lindex $chr 0]]] [html [strip_html [lindex $chr 1]]][color] [color blue on white]$cn[color]"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment