- Код: Выделить всё
- namespace eval ::yainfo {
 bind pub - !инфо ::yainfo::pub
 set ::yainfo::redir 0
 
 proc pub {nick uhost hand chan text} {
 ::http::config -useragent "Opera 9.52 (Windows NT 5.1; U; ru_RU)"
 set t [::http::geturl http://www.yandex.ru/ -timeout 20000]
 set data [::http::data $t]
 ::http::cleanup $t
 set a ""; set b ""; set c ""; set c1 ""
 ::egglib::writedata "yainfo.html" [list $data]
 if {![regexp -nocase -- {.*\">Погода</a>\ (<a href.+?)</dl></div>.*Котировки(.+?)\">Нефть</a></th.*\">Пробки<i></i></a><b>(.+?)</b>.*cmr\">(.+?)</a></em></div>.*} $data - a b c c1] && $::yainfo::redir <= 2} {incr ::yainfo::redir; putlog "::yainfo:: parse error -> trying again..."; pub $nick $uhost $hand $chan $text; return}
 if {$::yainfo::redir >= 2} {putserv "NOTICE $nick :Parser error!"; set ::yainfo::redir 0; return}
 #putlog "$c :: $c1"
 if {$a ne ""} {
 regsub -nocase -- "<!.*/h2><dl><dt>" $a "° C, " a
 regsub -nocase -- "<a href.*title=\"" $a "" a
 set a [string map -nocase {"\">" ", температура: сейчас" "</a>" "" "<b>" "" "</b>" "" "<dd>" "" " <dt>" "° C, "} $a]
 set usd ""; set eur ""; set probki ""
 set b [string map {"−" "-"} $b]
 #putlog "::yainfo:: b=$b"
 regexp -nocase -- {.*Динамика\ курса\ USD.*<td><strong(.+?)<tr><th><a href.*Динамика\ курса\ EUR.*<td><strong(.+?)<tr><th><a href.*Динамика\ индекса\ ММВБ} $b -> usd eur
 regsub -all -nocase -- "<.*>" $c1 "" c1
 if {$c ne ""} {append probki "$c"}
 if {$c1 ne ""} {append probki " \($c1\)"}
 set probki [string trim $probki]
 regsub -all -nocase -- "</strong><td>" $usd " руб. \(" usd
 regsub -all -nocase -- "</strong><td>" $eur " руб. \(" eur
 regsub -all -nocase -- "<.*>" $usd "" usd
 regsub -all -nocase -- "<.*>" $eur "" eur
 set usd [regsub -all -nocase -- "class.*\>|\>" $usd ""]
 set eur [regsub -all -nocase -- "class.*\>|\>" $eur ""]
 set msg ""
 if {$probki ne ""} {append msg "\00310\[Подольск\]\003:: \002Пробки\002: [string tolower $probki] ::"}
 if {$usd ne "" && $eur ne ""} {append msg " \002Курс USD\002: $usd\; \002Курс EUR\002: $eur ::"}
 if {$a ne ""} {append msg " \002За окном\002: [string tolower [string index $a 0]][string trimright [string range $a 1 end]]° C."}
 putfast "NOTICE $nick :$msg"
 set ::yainfo::redir 0
 }
 }
 putlog "yainfo loaded"
 }





