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.

Help with egghelp.tcl

Help for those learning Tcl or writing their own scripts.
Post Reply
r
ryal
Voice
Posts: 35
Joined: Thu May 12, 2005 6:10 pm

Help with egghelp.tcl

Post by ryal »

Hi !
Im trying to parse the content of a webpage but it doesnt work (it does tho with some webpages but not with www.google.com).
Heres the code i use:
proc parse_proc { nick uhost handle arg } {
global mychan sock

set d [date:offset [clock seconds] %m%d%y]
set url "http://www.google.com"
set target $nick
set sock [egghttp:geturl $url [list parseinfo $target $url] -timeout 600]
puthelp "PRIVMSG $target :$url"
}

proc parseinfo {target url sock} {
set headers [egghttp:headers $sock]
set body [egghttp:data $sock]
puthelp "PRIVMSG $target :hello"
puthelp "PRIVMSG $target :$headers"
puthelp "PRIVMSG $target :$body"
}
It displays the right url, "hello" and then nothing. I know body is a big variable but it should display the first line (which it does for some websites, but not with google). Of course i loaded egghelp.tcl in my *.conf and it loads alright.
What did i do wrong? i do believe the error stands in the way i call egghttp:geturl but i dont know how to fix it
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

3 things:
- try using a shorter timeout than 10min :D
- try using the header line "Connection: close"
- Try passing only the first line to puthelp via [string range $body 0 [string first $body "\n"]]. That saves your bot getting various errors from IRC Server and most likely getting spammed out (if it isnt trimmed to 510 bytes anyway)

Btw. headers also contain about 5-10 lines depending on HTTP server.
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...
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

egghttp is outdated, do not use it

use Tcl's built-in http package instead
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
r
ryal
Voice
Posts: 35
Joined: Thu May 12, 2005 6:10 pm

Post by ryal »

Thx for the tip, didnt know there was a built in package.
Anyway, i still get the same error (that is http::data returns an empty string, no url data). Heres the new code:

Code: Select all

proc parse_proc { nick uhost handle arg } {
	global sock

	set url "http://www.google.com"
	set target $nick
	set sock [::http::geturl $url -command [list parseinfo $target $url] -timeout 60]
	puthelp "PRIVMSG $target :$url"
}

proc parseinfo {target url sock} {
	set body [::http::data $sock]
	::http::cleanup $sock
	
	set body2 [string range $body 0 [string first $body "\n"]]
	puthelp "PRIVMSG $target :hello"
	puthelp "PRIVMSG $target :$body hello2"
}
It displays the url, "hello" and then "hello2" with nothing in front of it.
Any ideas?

PS: of course the timer wasnt 10' at first ;) i just wanted to know if it could be a timer pb so i put an extra large.
Thanks for your help guys!
Last edited by ryal on Tue Dec 20, 2005 12:03 pm, edited 1 time in total.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

try using it in the simpler, blocking form first - i.e. without -command switch

and use

Code: Select all

 tag when posting code, not [quote]
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
r
ryal
Voice
Posts: 35
Joined: Thu May 12, 2005 6:10 pm

Post by ryal »

I get exactly the same result without the "-command".
Could this be a bug from the http package?
PS: sorry the for quote instead of code; i just fixed it
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

nope, it's bug in your script or/and your logic
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
Post Reply