egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

incith:layout ~ a base script for http scripts

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
incith
Master


Joined: 23 Apr 2005
Posts: 275
Location: Canada

PostPosted: Fri Sep 16, 2005 6:58 pm    Post subject: incith:layout ~ a base script for http scripts Reply with quote

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. Smile 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.
_________________
; Answer a few unanswered posts!


Last edited by incith on Wed Dec 24, 2008 4:16 am; edited 2 times in total
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Fri Sep 16, 2005 10:42 pm    Post subject: Reply with quote

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 Wink
_________________
connection, sharing, dcc problems? click <here>
before asking for scripting help, read <this>
use [code] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
incith
Master


Joined: 23 Apr 2005
Posts: 275
Location: Canada

PostPosted: Fri Sep 16, 2005 11:58 pm    Post subject: Reply with quote

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~
_________________
; Answer a few unanswered posts!
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Sat Sep 17, 2005 12:22 am    Post subject: Reply with quote

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

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] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
incith
Master


Joined: 23 Apr 2005
Posts: 275
Location: Canada

PostPosted: Sat Sep 17, 2005 4:41 pm    Post subject: Reply with quote

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?
_________________
; Answer a few unanswered posts!
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Sat Sep 17, 2005 5:33 pm    Post subject: Reply with quote

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] tag when posting logs, code
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber