package require http bind pub - .nhl nhl proc nhl {n u h c t} { if {$t == ""} { set search "*" } else { set search "*[join [lindex [split $t] 0]]*" } set x [::http::geturl http://mobileapp.espn.go.com/nhl/mp/html/scoreboard] set e [split [::http::data $x] \n] # it seems all the data is on the first line of the html, so we'll just use that set e [lindex $e 0] set line_found 0 set matches "" set time "" set score "" set count 0 # brings us closer to the data regexp {
.+
.+
} $e e # pulls out each game of data while { [regexp {.+
.+
} $e matches] && $count < 100} {\ incr count set e $matches if {[string match -nocase $search $matches]} { set myRegExp [regexp {(.+?)
(.+?)
} $matches matches time score] if {$myRegExp && [string match -nocase $search $matches]} { # if we have scores and not TEAM at TEAM, make the scores bold if { ![regexp {[A-z0-9\.' ]+? at [A-z0-9\.' ]+?} $score] } { incr line_found set team1 "" set team2 "" set score1 "" set score2 "" regexp {([A-z0-9\.' ]+?) ([0-9]+?) ([A-z0-9\.' ]+?) ([0-9]+?)} $score _ team1 score1 team2 score2 regsub -all { / } $time {/} time set score "$team1 \002$score1\002 $team2 \002$score2\002" set score [string toupper $score] set time [string toupper $time] # print out time and score for this line puthelp "privmsg $c :$score ($time)" } elseif { $search != "*" } { incr line_found set score [string toupper $score] set time [string toupper $time] # print out time and score for this line puthelp "privmsg $c :$score ($time)" } } } # gives us the remaining games to loop through, without the one we've just printed # if there isn't anymore, break out of while loop set pattern {.+?
.+?
(.+
.+
$)} if { ![regexp $pattern $e _ e] } { if {$line_found == 0} { if { $search == "*" } { putserv "PRiVMSG $c :Wrong arguments used, try '.nhl \[search-term\]'" } putserv "privmsg $c :There are no current scores for today." } break } } }