Code: Select all
# 1 : notice $nick
# 2 : privmsg $nick
# 3 : privmsg $channel
set cricketmethod 2
### Events
bind pub - "!rating" rating
package require http
proc rating {nick uhost handle channel text} {
switch -- [string tolower [lindex [split $text] 0]] {
odi {
rating:download $nick $channel odi
}
test {
rating:download $nick $channel test
}
default {
putquick "NOTICE $nick :Commands:"
putquick "NOTICE $nick :!rating ODI"
putquick "NOTICE $nick :!rating TEST"
}
}
}
proc rating:download {nick chan class} {
global data
switch -exact -- $::cricketmethod {
"1" {set method "notice" ; set who "$nick"}
"2" {set method "privmsg" ; set who "$nick"}
"3" {set method "privmsg" ; set who "$chan"}
}
putlog "Reply 2."
set url "http://icc-cricket.yahoo.com/rankings/rankings.html"
set data [getwebdata $url]
if {$data==0} {
putserv "$method $who :There was an error fetching the data. Contact an admin to report this or try again later."
return
}
putlog "Reply 3."
set foundstart 0
putlog "Reply 4."
foreach line [split $data \r\n] {
putlog "Reply 5."
putlog [string match "<div id=\"rankings-header\"><a name=\"$class\">" $line]; putlog "line:$line";
if {[string match -nocase "<div id=\"rankings-header\"><a name=\"$class\">" $line]} {
putlog "Reply 6."
set word "\037\002[string range $line [expr 40 + [string length $class] -3] [expr [string length $line]-11]]\002\037"
regsub -all {Reliance Mobile ODI Championship} $word "\00300,04ICC ONE-DAY Cricket Ratings.\003" word
regsub -all {Reliance Mobile Test Championship} $word "\00300,03ICC TEST Cricket Ratings.\003" word
putserv "$method $who :$word"
putlog "Reply 1."
set foundstart 1
set output ""
} elseif {$foundstart && [string match -nocase {<div class="rankings_bottom">*</div>*} $line]} {
# output the date
regsub -all "<div style=\"float:left;padding-left:10px;\">" $info " " info
## regsub -all -- {<div .*?>} $line "" line
## regsub -all -- {</div>} $line " " line
set word [string range $line 29 [expr [string length $line]-15]]
putserv "$method $who :$word"
return
} elseif {$foundstart} {
# firstcol - the ranking
if {[string match -nocase {<div class="firstcol">*</div>} $line]} {
set word [string range $line 25 [expr [string length $line]-11]]
append output "[format %-3s $word]"
# secondcol = info bold
} elseif {[string match -nocase {<div class="secondcol"><b>*</b></div>} $line]} {
set word [string range $line 26 [expr [string length $line]-11]]
append output "[format %-16s "\002$word\002"]"
# secondcol = info normal
} elseif {[string match -nocase {<div class="secondcol">*</div>} $line]} {
set word [string range $line 23 [expr [string length $line]-7]]
append output "[format %-15s $word]"
# output everything
} elseif {[string match -nocase {</div>} $line]} {
putserv "$method $who :$output"
set output ""
}
}
}
}
Code: Select all
putlog "Reply 5."
putlog [string match "<div id=\"rankings-header\"><a name=\"$class\">" $line]; putlog "line:$line";
if {[string match -nocase "<div id=\"rankings-header\"><a name=\"$class\">" $line]} {
Can anyone tell me what could be the problem?
Thanks.
iamdeath