This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

id lookup with HTTP POST

Old posts that have not been replied to for several years.
Locked
k
kanibus
Halfop
Posts: 44
Joined: Tue May 03, 2005 7:22 am

id lookup with HTTP POST

Post by kanibus »

hello, i am trying to write something that will use an id lookup on www.czleague.org and display the results in the chat, at the request of a user. a POST request to
index.php?div=&action=steamidsearch&submit=1 with one argument as steamid is required.

Code: Select all

set cztrig .czlid
bind PUB -|- $cztrig steam_query

proc steam_query { nick host hand chan text } {

        if { [string match "" "$text"] } {
                putserv "NOTICE $nick :usage: .czlid <steamid>      example: .czlid 0:1:2345"
        } else {
        search_id $nick "czleague.org/index.php?div=&action=steamidsearch&submit=1" $text
        }
}

proc search_id {ic url string} {

        ::http::config -useragent "Kanibus's CZLid Search"
        set czid [::httpformatQuery:: steamid $string]
        if {[catch {set tok [::http::geturl $url -query $czid]} error]} {
                set text "An error occured while connecting to the CZL database."
                putserv "NOTICE $ic :$text"
                return
        }
        if {[::http::ncode $tok] != 200} {
                set text "An error occured while connecting to the CZL database."
                putserv "NOTICE $ic :$text"
                ::http::cleanup $tok ; return
        }
        set data [html2text [::http::data $tok]]
       ###PARSE HERE??###
        set text "results here"
        putserv "NOTICE $ic :$text"
        ::http::cleanup $tok ; return

}
proc html2text {text} {
        regsub -all {<.*?>}  $text {}    text
        regsub -all { } $text { }   text
        regsub -all {<}   $text {<}   text
        regsub -all {>}   $text {>}   text
        regsub -all {"} $text {\\"} text
        regsub -all {'}  $text {'}   text
        regsub -all {[}  $text {\\[} text
        regsub -all {]}  $text {\\]} text
        regsub -all {©} $text {©}   text
        regsub -all {&}  $text {&}   text
        return $text
}

putlog "czl.tcl - steam id lookup - kanibus(rbrady0819@yahoo.com)" 
Last edited by kanibus on Tue May 03, 2005 10:24 am, edited 1 time in total.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

Code: Select all

# http::formatQuery --
#
#	See documentaion for details.
#	Call http::formatQuery with an even number of arguments, where 
#	the first is a name, the second is a value, the third is another 
#	name, and so on.
#
# Arguments:
#	args	A list of name-value pairs.
#
# Results:
#        TODO
seems you have to rather use

Code: Select all

set czid [::http::formatQuery steamid $string]
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
k
kanibus
Halfop
Posts: 44
Joined: Tue May 03, 2005 7:22 am

Post by kanibus »

ahh woops good eye on that one, is ther a way to do something like debugging where i can see if the bot is getting hung up on the post or where it gets stuck beacuse there are no errors in the logs but yet it doesnt return anything. i tried to do the following to get $data written to a text file so i will be able to parse it, without luck.

Code: Select all

        set resfile "/home/luser/eggdrop/scripts/search.results"
        set fx [open $resfile w]
        puts $fx "$data"
        close $fx
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

if any TCL error occur you can see them in $errorInfo (usually: .set errorInfo).
if it doesnt write anything, then it doesnt come so far ^-^.
I have often used similar codes to save the html code.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
k
kanibus
Halfop
Posts: 44
Joined: Tue May 03, 2005 7:22 am

Post by kanibus »

thanks a lot for your help. i got it writing to the file, but i am having trouble parsing this. is there a way i could add these items to a list by line? i tried [split $data >] )to split it after the > character without using the htlm2tect proc)and that didnt work so if i can just do it by line in a list than search that list for the strings, but ive cant figure out how. thanks in advance.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

you want to split each line input an element of a list?
then use: [split $data \n]
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
k
kanibus
Halfop
Posts: 44
Joined: Tue May 03, 2005 7:22 am

Post by kanibus »

thanks again for your help, here is the finished product:

Code: Select all

set cztrig .czlid
bind PUB -|- $cztrig steam_query

proc steam_query { nick host hand chan text } {

        if { [string match "" "$text"] } {
                putserv "NOTICE $nick :usage: .czlid <steamid>      example: .czlid 0:1:2345"
        } else {
        search_id $nick "czleague.org/index.php?div=&action=steamidsearch&submit=1" $text
        }
}

proc search_id {ic url string} {

        ::http::config -useragent "Kanibus's CZLid Search"
        set czid [::http::formatQuery steamid $string]
        if {[catch {set tok [::http::geturl $url -query $czid]} error]} {
                set text "An error occured while connecting to the CZL database."
                putserv "NOTICE $ic :$text"
                return
        }
        if {[::http::ncode $tok] != 200} {
                set text "An error occured while connecting to the CZL database."
                putserv "NOTICE $ic :$text"
                ::http::cleanup $tok ; return
        }
        set data [html2text [::http::data $tok]]
        set dalist [split $data \n]
        set first [lsearch $dalist Alias]
        set second $first
        incr first 4
        incr second 7
        set results [lrange $dalist $first $second]
        set daid [lindex $results 0]
        set daname [lindex $results 1]
        set lastname [lindex $results 2]
        set daalias [lindex $results 3]
        #set resfile "/home/kanibus/eggdrop/scripts/search.results"
        #set fx [open $resfile w]
        #puts $fx "$results"
        #close $fx
        set text "\0037,1\037S\037\0030,1team id:\0037,1 $daid \0030,1· \0037,1\037N\037\0030,1ame:\0037,1 $daname $lastname \0030,1· \0037,1\037A\037\0030,1li
        putserv "NOTICE $ic :$text"
        ::http::cleanup $tok ; return

}
proc html2text {text} {
        regsub -all {<.*?>}  $text {}    text
        regsub -all { } $text { }   text
        regsub -all {<}   $text {<}   text
        regsub -all {>}   $text {>}   text
        regsub -all {"} $text {\\"} text
        regsub -all {'}  $text {'}   text
        regsub -all {[}  $text {\\[} text
        regsub -all {]}  $text {\\]} text
        regsub -all {©} $text {©}   text
        regsub -all {&}  $text {&}   text
        return $text
}

putlog "czl.tcl - steam id lookup - kanibus(rbrady0819@yahoo.com)"
k
kanibus
Halfop
Posts: 44
Joined: Tue May 03, 2005 7:22 am

Post by kanibus »

i tried to add some more functionality but it gives me a tcl error saying that the value of deediv isnt a command, like say deediv was "m" it says
Tcl error [steam_query]: invalid command name "m"

Code: Select all

set cztrig .czlid
bind PUB -|- $cztrig steam_query

proc steam_query { nick host hand chan text } {

        if { [string match "" "$text"] } {
                putserv "NOTICE $nick :usage: .czlid <steamid>      example: .czlid 0:1:2345"
        } else {
        search_id $nick "czleague.org/index.php?div=&action=steamidsearch&submit=1" $text
        }
}

proc search_id {ic url string} {
        global dateem deediv dateam idee
        set dateem ""
        set dateam ""
        set deediv ""
        ::http::config -useragent "Kanibus's CZLid Search"
        set czid [::http::formatQuery steamid $string]
        if {[catch {set tok [::http::geturl $url -query $czid]} error]} {
                set text "An error occured while connecting to the CZL database."
                putserv "NOTICE $ic :$text"
                return
        }
        if {[::http::ncode $tok] != 200} {
                set text "An error occured while connecting to the CZL database."
                putserv "NOTICE $ic :$text"
                ::http::cleanup $tok ; return
        }
        set undata [::http::data $tok]
        regexp {<a href="index.php\?div=&action=viewuser&id=([0-9]*)">View</a></td>} $undata - idee
        set turl "czleague.org/index.php?div=&action=viewuser&id=$idee"
        if {[info exists idee]} {
        if {[catch {set tak [::http::geturl $turl]} error]} {
                set dateam "unavailible"
                return
              }
        if {[::http::ncode $tak] != 200} {
                set dateam "unavailible"
                ::http::cleanup $tak ; return
        }
        set ttdata [::http::data $tak]
        regexp {<a href="index.php\?div=czl(.*)&action=viewteam&id=([0-9]*)">(.*)</a>} $ttdata - deediv deeeideee dateem
        if {[info exists dateem]} {
        global deediv
        if {[info exists deediv]} {
        if {[$deediv == "o"]} {
        set saydiv "(open)"
        } elseif {[$deediv == "m"]} {
        set saydiv "(main)"
        } elseif {[$deediv == "i"]} {
        set saydiv "(invite)"
        } else {
        set saydiv ""
         }
        }
        set dateam [html2text $dateem]
        ::http::cleanup $tak
        } else {
        set dateem "Clanless"
        set dateam "Clanless"
        }
        } else {
        set dateam "unavailible"
        }
        set data [html2text $undata]
        set dalist [split $data \n]
        set first [lsearch $dalist Alias]
        set second $first
        incr first 4
        incr second 7
        set results [lrange $dalist $first $second]
        set daid [lindex $results 0]
        set daname [lindex $results 1]
        set lastname [lindex $results 2]
  set daalias [lindex $results 3]
        if {$dateam == "" } { set dateam "Clanless" }
        if {$daid == "" } {
        set text "\0037,1\037S\037\0030,1orry, that id was not found in the database."
        } else {
        set text "Steam id: $daid · Name: $daname $lastname · Alias: $daalias · Team: $dateam $saydiv"

    }
        putserv "NOTICE $ic :$text"
        ::http::cleanup $tok ; return

}

proc html2text {text} {
        regsub -all {<.*?>}  $text {}    text
        regsub -all { } $text { }   text
        regsub -all {<}   $text {<}   text
        regsub -all {>}   $text {>}   text
        regsub -all {"} $text {\\"} text
        regsub -all {'}  $text {'}   text
        regsub -all {[}  $text {\\[} text
        regsub -all {]}  $text {\\]} text
        regsub -all {©} $text {©}   text
        regsub -all {&}  $text {&}   text
        return $text
}

putlog "czl.tcl - steam id lookup - kanibus(rbrady0819@yahoo.com)"

why is it trying to use the value of deediv as a command? i dont see when i am calling it?
k
kanibus
Halfop
Posts: 44
Joined: Tue May 03, 2005 7:22 am

Post by kanibus »

could if be the [info exists deediv] should i put a $ in front of deediv?
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

no, he mussn't.

here is the error:
if {[$deediv == "o"]} {

dont use [] around such an expression, this will try to call the content of the var as a function with the argument '== "o"' and triing to handle return value as boolan.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Locked