Code: Select all
package require http
bind pub - -projects aproc
proc aproc {n u h c t} {
set token [::http::geturl http://www.tclscript.com/scripts.shtml]
set data [::http::data $token]
# parse $data, see how many project lines there is
puthelp "privmsg $c :total number of projects: $total"
::http::cleanup $token
}
Code: Select all
# parse $data, see how many project lines there is
Code: Select all
set total 0
foreach line [split [::http::data $token] \n] {
if [string match *someprojectpattern* $line] {incr total}
}
Code: Select all
# egghttp_example.tcl
# Config
set url "http://www.tclscript.com/scripts.shtml"
set dcctrigger "example"
# End of config
if {![info exists egghttp(version)]} {
putlog "egghttp.tcl was NOT successfully loaded."
putlog "egghttp_example.tcl has not been loaded as a result."
} else {
proc your_callbackproc {sock} {
global url
set headers [egghttp:headers $sock]
set body [egghttp:data $sock]
regsub -all "\n" $body "" body
regsub -all -nocase {<br>} $body "<br>\n" body
regexp {Total Projects: <u>(.*)</u>} $body - served
puthelp "PRIVMSG #macked :There are total of $served projects so far."
}
bind dcc o|o $dcctrigger our:dcctrigger
proc our:dcctrigger {hand idx text} {
global url
set sock [egghttp:geturl $url your_callbackproc]
return 1
}
putlog "egghttp_example.tcl has been successfully loaded."
}
Code: Select all
set url "www.tclscript.com"
proc get_projects {nick uhost handle channel text} {
global url
set sock [socket $url 80]
fconfigure $sock -buffering line -buffersize 1000
puts $sock "GET /scripts.shtml HTTP/1.0"
puts $sock "Host: www.tclscript.com"
puts $sock ""
flush $sock
while {![eof $sock]} {
gets $sock body
regexp -all {Total Projects: <u>(.*)</u>} $body _ served
}
if {[eof $sock]} { close $sock }
regsub -all {(<.+?>)} $served "" served
puthelp "PRIVMSG $channel :www.tclscript.com has a total of [lindex $served 0] projects so far."
}
bind pub - !projects get_projects