-
-
Save ryanfb/13898 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { } [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