bind pub - !rates fx
set needrates "EUR/USD USD/JPY EUR/JPY"
proc fx {nick uhost hand chan text} {
global needrates
::http::config -useragent "UserAgent"
set tok [::http::geturl "http://www.fxstreet.com/rates-charts/currency-rates/" -timeout 15000]
set data [::http::data $tok]
::http::cleanup $tok
regsub -all -- {\n} $data "" data
regsub -all -- {\s+} $data " " data
putserv "PRIVMSG $chan :Name - Last - Open - High - Low - Net chg. - Chg. % Last Time"
regexp -- {<table width="100%" style="cursor:pointer">(.*?)</table>} $data "" a
regsub -all -- {</tr>} $a "|" a
regsub -all -- {<td.*?>} $a "" a
foreach line [lrange [split $a "|"] 1 end] {
regexp -- {<tr .*?> (.*?)</td> (.*?)</td> (.*?)</td> (.*?)</td> (.*?)</td> (.*?)</td> (.*?)</td> (.*?)</td>} $line "" b c d e f g h j
foreach rate [split $needrates " "] {
if {$b == $rate} {
putserv "PRIVMSG $chan :$b - $c - $d - $e - $f - $g - $h - $j"
}
}
}
}