rendered paste bodybind pub -|- !items pub:getinfo
proc pub:getinfo {nick uhost hand chan arg} {
set content [split [getwebdata "http://www.bignetwork.se/count.php"] " "]
set count [lindex $content 0]
putserv "privmsg $chan :Det finns $count st items i databasen."
}
package require http
## getwebdata {URL}
proc getwebdata {u} {
global getweb
::http::config -useragent Mozilla
if {[catch {::http::geturl $u -timeout 20000} id]} {
#puts "\[GetWeb Error\] $u : $id"
return 0
} elseif {[::http::status $id]=="timeout"} {
#puts "\[GetWeb Error\] $u : timeout"
::http::cleanup $id
return 0
} elseif {[string match -nocase ok [set e [::http::code $id]]]} {
#puts "\[GetWeb Error\] $u : $e"
::http::cleanup $id
return 0
} {
set info [::http::data $id]
::http::cleanup $id
return $info
}
}
#urlencode
proc urlencode {text} {
set url ""
foreach byte [split [encoding convertto utf-8 $text] ""] {
scan $byte %c i
if {[string match {[%<>"]} $byte] || $i <= 32 || $i > 127} {
append url [format %%%02X $i]
} else {
append url $byte
}
}
return $url
}