All pastes #757684 Raw Edit

Mine

public text v1 · immutable
·published 2007-11-01 15:05 UTC
rendered paste body
bind pub -|- !foo 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 :There are $count places available."
}

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
}

#urldecode
proc urlIntDecode {url} {
  set matches [regexp -all -inline -- {&#[[:digit:]]{2,3};} $url]
  set map {}
  foreach m $matches {
    if {[set r [string range $m 2 end-1]]<128} {
      lappend map $m [format %c $r]
    }
  }
  return [string map $map $url]
}