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 

Yet another "fetch info from the web" Request.

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
CraXyOW3
Voice


Joined: 18 Jun 2006
Posts: 1

PostPosted: Sun Jun 18, 2006 1:33 am    Post subject: Yet another "fetch info from the web" Request. Reply with quote

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:
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 Razz
(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.
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Thu Jun 29, 2006 5:08 am    Post subject: Reply with quote

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:

#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.
Back to top
View user's profile Send private message
urban
Voice


Joined: 28 Jul 2006
Posts: 3

PostPosted: Fri Jul 28, 2006 7:26 pm    Post subject: Reply with quote

Quote:
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 ?
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Fri Jul 28, 2006 9:04 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
urban
Voice


Joined: 28 Jul 2006
Posts: 3

PostPosted: Sat Jul 29, 2006 8:29 am    Post subject: i am using this code but i still get the no such var Reply with quote

Code:

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
Back to top
View user's profile Send private message
krimson
Halfop


Joined: 19 Apr 2006
Posts: 86

PostPosted: Sat Jul 29, 2006 8:39 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail
urban
Voice


Joined: 28 Jul 2006
Posts: 3

PostPosted: Sat Jul 29, 2006 1:52 pm    Post subject: Reply with quote

Anybody help ?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests 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