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.

incith:layout ~ a base script for http scripts

Support & discussion of released scripts, and announcements of new releases.
Post Reply
User avatar
incith
Master
Posts: 275
Joined: Sat Apr 23, 2005 2:16 am
Location: Canada

incith:layout ~ a base script for http scripts

Post by incith »

I will be working on this, and this will become my updated :weather and :google scripts, and so on, but before I do that I'd like some feedback from the gurus of the forums, any optimizations you can offer, ideas, cleanups, etc..

I realize my name is branded all over this, namespaces are a GOOD thing, feel free to find/replace my name if you use this. :) I wouldn't want somebody elses variables being mixed into my namespaces anyway.. which is the whole point of namespaces. =)

I've tried to code all the things people e-mail me about, at the moment this is missing flood protection & line wrapping, as I want to clean the ones I do use up considerably before I add them to this.. it has proxy support for the http requests, and uses an array for the parsed html data.

12/24/2008 - plans to update this thread in due time.
Last edited by incith on Wed Dec 24, 2008 4:16 am, edited 2 times 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 »

I am not sure whether this should be bare-bones stand-alone script, I'd rather go for a package providing some standard pre-parsing, not bothering with eggdrop implementation details (binds, channels, privmsgs, etc.)

also, you should use asynchronous [::http::geturl], you wouldn't want to clog the bot even for a second because of unresponsive websites; besides, the whole eggdrop philosophy is based on event-driven I/O, so you should stick with that

namespaces are good idea, even with your name as bumper sticker ;)
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
User avatar
incith
Master
Posts: 275
Joined: Sat Apr 23, 2005 2:16 am
Location: Canada

Post by incith »

Hey, thanks for replying. I still like the idea of a script-based layout, it's easy for me to hack something together for whatever I want to parse. =)

I know the old don't use regexps to parse html. I like to.

Anyway, I updated for v1.1, nothing major, the beginnings of send_output, which will one day contain a smart line wrapping algo, and so on.

I'll look into async lookups.. there's also bgExec, of which a pure-Tcl implementation exists at http://wiki.tcl.tk/12704

Regards~
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

this could spare you some time for async research, it's an excerpt from my rss script:

Code: Select all

proc fetch {url chan} {
	variable timeout
	variable version; variable token
	set to [expr {$timeout * 1000}]
	set cmd [namespace current]::callback
	::http::config -useragent "$version by demond"
	if {[catch {set t [::http::geturl $url -command $cmd -timeout $to]} err]} {
		putlog "$version: ERROR($chan): $err"
	} {
		set token($t) $chan
	}
}

proc callback {t} {
	variable version; variable token
	set chan $token($t)
	switch -exact [::http::status $t] {
	"timeout" {
		putlog "$version: ERROR($chan): timeout"
	}
	"error" {
		putlog "$version: ERROR($chan): [::http::error $t]"
	}
	"ok" {
		if {[::http::ncode $t] != 200} {
			putlog "$version: ERROR($chan): [::http::code $t]"
		} {
			process [::http::data $t] $chan
		}
	}
	default {
		putlog "$version: ERROR($chan): got EOF from socket"
	}}
	::http::cleanup $t
}
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
User avatar
incith
Master
Posts: 275
Joined: Sat Apr 23, 2005 2:16 am
Location: Canada

Post by incith »

Pardon any potential ignorance and lack of testing this, the only thing that makes this asynchronous is the callback routine? In Perl I'd have to fork the process etc, just having a callback will work as expected?
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

incith wrote:Pardon any potential ignorance and lack of testing this, the only thing that makes this asynchronous is the callback routine? In Perl I'd have to fork the process etc, just having a callback will work as expected?
that is correct; you don't need to fork anything

any async activity in Tcl (implemented by any command that features callback) is done via Tcl's event loop, which you normally need to enter somehow (using [vwait] or [update]) when coding stand-alone Tcl app (for example, piped through tclsh); however, you don't have to do that in botscripts - eggdrop already does it for you, i.e. calls Tcl_DoOneEvent() in its main event loop
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use

Code: Select all

 tag when posting logs, code
Post Reply