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.

Yet another "fetch info from the web" Request.

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
C
CraXyOW3
Voice
Posts: 1
Joined: Sun Jun 18, 2006 12:47 am

Yet another "fetch info from the web" Request.

Post by CraXyOW3 »

Well, where should i start then.

Ok, i have been a user of mIRC for a very long time and has always been a wannabe *nix user and always out to broaden my knowledge of things.
Now i have found eggdrop and tried alot of scripts and worked my way around to customise it.
The problem i got now is that i have forgotten how the heck i made my mIRC script work and dont have a clue on how to proceed to convert it to TCL even if they are both quite similar to eachoter.

What this script does then?
1. Channel user types " !akfind keyword" in channel.
2. Script recognizes it.
3. Script connects to server and gets information depending on keywords.
4. The page is loaded and gives results according to keywords.
5. Script saves a temp file with information.
6. Script notices user the results from the find.
7. Script deletes temp file.

What i cant seem to figure out is the delay on notice and posting multiple lines of information to user.

I would appreciate a complete conversion of this and i would appreciate it even more if i got alot of hints and tips instead, on how to proceed with this!

Btw, i have searched this place, the all knowing google and some other resources too but failed.

Here is the mIRC script:

Code: Select all

alias akfind {
  var %sockname = $+(akfinder.,$ctime,.,$replace($1-,$chr(32),.))
  if ($sock(%sockname)) { return }
  sockopen %sockname localhost 80
  sockmark %sockname http_connect $1 $2-
}
on *:text:.akfind *:#:{
  akfind $nick $2-
}
on *:sockopen:akfinder.*:{
  tokenize 32 $sock($sockname).mark
  sockwrite -n $sockname GET /irc.asp?get= $+ $replace($3-,$chr(32),$+($chr(37),20)) HTTP/1.0
  sockwrite -n $sockname Host: localhost
  sockwrite -n $sockname Connection: Close
  sockwrite -n $sockname $crlf
}
on *:sockread:akfinder.*:{
  tokenize 32 $sock($sockname).mark
  var %tmp
  sockread %tmp
  if ($1 == http_connect) {
    if (!%tmp) { sockmark $sockname http_read $2- }
  }
  elseif ($1 == http_read) {
    if (%tmp == ---- start of find ----) { sockmark $sockname http_read_send $2- }
  }
  elseif ($1 == http_read_send) {
    if (%tmp == ---- eof of Find ----) { sockmark $sockname http_read $2- }
    else { write $+(tmpdata,$2) $2 $iif($remove(%tmp,-),$ifmatch,-) }
  }
}
on *:sockclose:akfinder.*:{
  tokenize 32 $sock($sockname).mark
  .play -n $2 $+(tmpdata,$2)
  .remove $+(tmpdata,$2)
}
For those who want to try using the webpage it is located here:
http://craxxe.sytes.net/irc.asp?get=keyword
as this is an anime related thing you can try any title you wish. example "burn" "chobits" "bebop".

I have also worked with package http and egghttp but i quite dont get it yet, this is the closest to the finished thing ive found -> http://www.tclscript.com/egghttp_tut.shtml
But still, it only types out one line.

One last thing, the way the irc.asp files generates the file can be changed to anything else, as another older version of my mIRC script exchanged "-" signs to simple " " spaces, just the anser to all the "---" signs :P
(the site isnt up for the moment.)

EDIT
Hrm, i have been looking around some more and now i know for a fact that this script is doable, altho i am a novice at this still, i get confused while reading the code.
So far the script i have found sofar has helped me some (!bash script on this site) but i would still want some hints and tips on how to make this work.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

My isp is having fits as usual, so I can't connect to the site to look at the html to make a template. If you can post the raw html code to show what data you're looking to grab, I'm sure we can make a regex to get the data in to a usable format.

As far as how to make a basic tcl script to grab the webpage:

Code: Select all

#sample html grabber script
package require http 2.3
bind pub - !geturl geturlproc

proc geturlproc {nick uhost hand chan text} {
     set text [string trim $text]
     set text [split $text]
     set url "http://craxxe.sytes.net/irc.asp?get="
     catch {set page [::http::geturl $url[join $text] -timeout 90000]} error
     if {[string match -nocase "*couldn't open socket*" $error]} {
                puthelp "PRIVMSG $nick :Error: couldn't connect.."
                ::http::cleanup $page
                return
     }
     if { [::http::status $page] == "timeout" } {
                puthelp "PRIVMSG $nick :Error: Connection timed out."
                ::http::cleanup $page
                return
     }

     set html [::http::data $page]
     ::http::cleanup $page

      foreach line {[split $html \n]} {
                if {[regexp -nocase {<distinguishing html code data>(.*?)<more html code>} $html match gottextmatchvar]} {
                    puthelp "PRIVMSG $nick :Here's the data: [join $gottextmatchvar]"
                }
      }
}
Read the regexp page and re_syntax manual pages about () used for reporting matches, essentially everything within (.*?) is what is captured into a variable. You can capture more than 1 thing into multiple vars in the same regexp.

The script I just wrote for "This Day In History" might be a good example:
http://members.dandy.net/~fbn/tdih.tcl.txt

Hope this helps.
u
urban
Voice
Posts: 3
Joined: Fri Jul 28, 2006 7:24 pm

Post by urban »

bind pub - !geturl geturlproc

proc geturlproc {nick uhost hand chan text} {
set text [string trim $text]
set text [split $text]
set url "http://craxxe.sytes.net/irc.asp?get="
catch {set page [::http::geturl $url[join $text] -timeout 90000]} error
if {[string match -nocase "*couldn't open socket*" $error]} {
puthelp "PRIVMSG $nick :Error: couldn't connect.."
::http::cleanup $page
return
}
if { [::http::status $page] == "timeout" } {
puthelp "PRIVMSG $nick :Error: Connection timed out."
::http::cleanup $page
return
}

set html [::http::data $page]
::http::cleanup $page

foreach line {[split $html \n]} {
if {[regexp -nocase {<distinguishing html code data>(.*?)<more html code>} $html match gottextmatchvar]} {
puthelp "PRIVMSG $nick :Here's the data: [join $gottextmatchvar]"
}
}
}
i try this and i get page var does not exsist i am using windrop !!

Any help ?
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

That would indicate that the geturl failed.. You can put

set page ""

Somewhere above the "catch {set page" part and then test to see if page is empty..

Don't know bout windrop, the script works for me in linux & bsd. I'm guessing that windrop's http is broke and does not set the var on failure.
u
urban
Voice
Posts: 3
Joined: Fri Jul 28, 2006 7:24 pm

i am using this code but i still get the no such var

Post by urban »

Code: Select all

proc test { nick user hand chan text } {
package require base64
set exp {http://([^\ ]+)(\ +)l:([^\ ]+)(\ +)p:(\w+)}

 		if {[regexp -nocase $exp $text full url x login y pass]} {
   		   
  	} else {
   		set exp {http://(.*):(.*)@(.*)}
   	if {[regexp -nocase $exp $text full login pass url path]} {
    		set url [lindex [split $url] 0]
    		

   } else {
    	
    	return 0
   }
 set collect "" 
   
putlog "workjing $url $login $pass"

catch { set collect [::http::geturl $url -timeout 3000 -headers [list Authorization "Basic [::base64::encode $login:$pass]"] } error 

if {[string match -nocase "*couldn't open socket*" $error]} {
                puthelp "PRIVMSG $chan :Error: couldn't connect..  "
                ::http::cleanup $collect
                return 0
     }
     putlog "$collect ssss"
     #if { [::http::status $collect] == "timeout" } {
               # puthelp "PRIVMSG $chan :Error: Connection timed out.  "
               # ::http::cleanup $collect
               # return 0
     #} 

if {[string match -nocase "*connect failed connection refused*" $error]} {
	puthelp "PRIVMSG $chan :Error: Connection refused..  "
                ::http::cleanup $collect
                return 0
     }
}
if { $collect == "" } { putlog "not working";return 0 }
putlog "worked"
}




using windrop
Last edited by urban on Sat Jul 29, 2006 8:40 am, edited 1 time in total.
User avatar
krimson
Halfop
Posts: 86
Joined: Wed Apr 19, 2006 8:12 am

Post by krimson »

you should put your code between [code] [/code] tags when posting any type of code or log. this will remove any smilies that may show up and make the code hard to read
u
urban
Voice
Posts: 3
Joined: Fri Jul 28, 2006 7:24 pm

Post by urban »

Anybody help ?
Post Reply