Code: Select all
############################################
# tv.com.tcl v0.2 by greenbear at gmail.com
#
# Parses tonights tv shows from tv.com
#
# Enable with .chanset #channel +tv
#
# offset to EST
# 6 hours makes sense for CET (Europe)
set tvoffset 6
bind pub - !tonight pub:tv.com
if ![info exists egghttp(version)] {
putlog "egghttp.tcl was NOT successfully loaded."
}
setudef flag tv
proc pub:tv.com {nick uhost hand chan text} {
if ![channel get $chan tv] return
set d [strftime %m%d%y]
set d [date:offset [clock seconds] %m%d%y]
set sock [egghttp:geturl http://www.tv.com/ [list parse:tv.com $chan] -headers "Cookie: tv_promo_$d=1"]
}
proc parse:tv.com {chan sock} {
set data [egghttp:data $sock]
egghttp:cleanup $sock
set data [string map {"\n" ""} $data]
set data [string map {"</tr>" "</tr>\n"} $data]
set data [string map {"</div>" "</div>\n"} $data]
set data [string map {"</td>" "</td>~"} $data]
set data [string map {"f-normal\">" "f-normal\">~"} $data]
set parse 0
foreach line [split $data \n] {
if [string match -noc "*<h3>What's On Tonight</h3>*" $line] {set parse 1}
if {$parse&&[string match -noc *</table>* $line]} {return}
if {$parse} {
regsub -all {<(.|\n)*?>} $line {} clean
set out [join $clean]
if {$out!=""&&$out!="~"&&![string match -noc "*What's On Tonight*" $out]} {
set ts [concat [lindex [split $out ~] 0]]
set ch [concat [lindex [split $out ~] 3]]
set sh [concat [lindex [split $out ~] 1]]
set ep [concat [lindex [split $out ~] 2]]
if ![regexp -nocase {[0-9]:[0-9][0-9][am|pm]} $out] {
putserv "PRIVMSG $chan :$sh \002\[\002\00304$ep\017\002\]\002 ($ch)"
} {
putserv "PRIVMSG $chan :$sh \002\[\002\00304$ep\017\002\]\002 ($ch at $ts)"
}
}
}
}
}
proc date:offset {epox arg} {
set t [expr $epox-((60*60)*$::tvoffset)]
set w [clock format $t -format $arg]
return $w
}
putlog "* tv.com.tcl loaded."