All pastes #763916 Raw Edit

Mine

public text v1 · immutable
·published 2007-11-06 20:52 UTC
rendered paste body
####################################################
#                      Rating                      #
####################################################


### Events
bind pub - "!rating" rating

proc rating {nick uhost handle channel text} {

  switch -- [string toupper [lindex [split $text] 0]] {
    ODI {
      rating:download $nick ODI /icc/odi/
    }
    TEST {
      rating:download $nick TEST /icc/test/
    }
    default {
      putquick "NOTICE $nick :Commands:"
      putquick "NOTICE $nick :!rating ODI"
      putquick "NOTICE $nick :!rating TEST"
    }
  }
}
proc rating:download {nick class url} {

  #--- Download Infos
  if {[catch {set sock "[socket www.icc-cricket.com 80]"} error] == "0"} {
    puts $sock "GET $url HTTP/1.0"
    puts $sock "Accept: text/html"
    puts $sock "Host: www.icc-cricket.com"
    puts $sock "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9)"
    puts $sock "Connection: close"
    puts $sock ""
    flush $sock

    #--- Header
    if {$class == "ODI"} {
      putquick "PRIVMSG $nick :\037\00300,04ICC ONE-DAY Cricket Ratings\003\037"
    } elseif {$class == "TEST"} {
      putquick "PRIVMSG $nick :\037\00300,03ICC TEST Cricket Ratings\003\037"
    }
    putquick "PRIVMSG $nick :\037Team                   Matches  Points  Rating\037"

    #--- Filtering Infos
    set x "0"
    while {[gets $sock html] >= "0"} {
      if {[string match -nocase "*<td *105* class=?panel-plain?>*" $html] == "1"} {
        set line "[join [gets $sock]]"
        set line "$line [string repeat " " [expr 12 - [string length "$line"]]]"
      } elseif {[string match -nocase "*<td class=?panel-icc-*? align=?center?>*" $html] == "1"} {
        set line "$line      [format %4.f [join [gets $sock]]]"
      } elseif {[string match -nocase "*<td *20* align=?right? class=?panel-icc-*?>*" $html] == "1"} {
        regexp {(.+)<br>} [gets $sock] match html
        if {[string match -nocase "*Rating*" $html] == "0"} {
          putquick "PRIVMSG $nick :[format %2.f [incr x]]. $line [string repeat " " [expr 35 - [string length "$line"]]] [format %3.f [join $html]]"
        }
      } elseif {[string match -nocase "*<font class=?small-text-pale?>*</font>*" $html] == "1"} {
        regexp {">(.+)</} $html match line
        if {$class == "ODI"} {
          putquick "PRIVMSG $nick :\037\00300,04${line}\003\037"
        } elseif {$class == "TEST"} {
          putquick "PRIVMSG $nick :\037\00300,03${line}\003\037"
        }
        break
      }
    }

    close $sock
  } else {
    putquick "NOTICE $nick :Timeout while querying Server."
  }
}