All pastes #355505 Raw Edit

Someone

public text v1 · immutable
·published 2007-02-14 15:01 UTC
rendered paste body
proc getRSS {siteid sitename url cookie proxy} {
variable mysql

putlog "Fetching $url"
if {![string equal $cookie ""]} {
set token [http::geturl $url -headers {Cookie "$cookie"}]
} else {
set token [http::geturl $url]
}
set rssdata [http::data $token]
http::cleanup $token

#puts $rssdata

set id [rss::parse $rssdata]
foreach item [$id items] {
     set name [string map {" " "_"} [$item title]]
     set response [mysqlsel $mysql(handle) "SELECT COUNT(*) FROM newsitems WHERE name='$name' AND site=$siteid" -flatlist]
     if {[string equal $response "0"]} {
     set response [mysqlsel $mysql(handle) "SELECT COUNT(*) FROM newsitems WHERE name='$name'" -flatlist]
     if {[string equal $response "0"]} {
     putquick "PRIVMSG #tr-beta :\002\003$sitename\003\002: \002#1\002 for \002$name\002"
     mysqlquery $mysql(handle) "INSERT INTO newsitems SET name='$name', site=$siteid, timestamp=[unixtime], pretime=[PreLookup $name], place=1, lostby=0"
     } elseif {[string equal $response "1"]} {
     putquick "PRIVMSG #tr-beta :\002\003$sitename\003\002: \002#2\002 for \002$name\002"
     mysqlquery $mysql(handle) "INSERT INTO newsitems SET name='$name', site=$siteid, timestamp=[unixtime], pretime=[PreLookup $name], place=2, lostby=1"
     } else {
     putquick "PRIVMSG #tr-beta :\002\003$sitename\003\002: \002#[expr ($response + 1)]\002 for \002$name\002"
     }
     }
}
utimer 10 getRSS $siteid $sitename $url $cookie $proxy
return 1
}

if {![info exists myproc_running]} {
    utimer 5 update
    set myproc_running 1
  }

proc update {} {
variable sites
#putquick "PRIVMSG #tr-beta :Updating..."
foreach site $sites {
getRSS [lindex $site 0] [lindex $site 1] [lindex $site 2] [lindex $site 3] [lindex $site 4]
}
return 1
}