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 

Eggdrop Web Information

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
karodde
Voice


Joined: 01 May 2007
Posts: 10

PostPosted: Thu May 03, 2007 7:19 am    Post subject: Eggdrop Web Information Reply with quote

Hello,
I need a script, which should do this:
When somebody in a channel types "!test", I want that my eggdrop automaticly posts a text/string. This text/string comes from a php or html file (http://www.site.com/thefile.html), i specified.
The Problem is, that the html source code contains much text, and I dont know how to tell the eggdrop, to post just the text/string I want.

By searching I found this example code:
Code:
bind pub - !example my:example

proc my:example {nick uhost hand chan text} {
  set url "http://your.web.server/page.php"
  set token [::http::geturl $url]
  set content [::http::data $token]
  ::http::cleanup $content
  foreach line [split $content \n] {
    putserv "PRIVMSG $chan :$line"
  }
}


When I use this script the whole html source code is posted by the eggdrop, but I only need one string.

Example:
Quote:
<html>

...code...

<tr><td bgcolor="#ffffff"><b>Here is any text</b><br>I want this</td><td bgcolor="#ffffff" align="right" valign="top">text...<b>text</b><br>more text and so on<b>text</b></td></tr>

...code...


This is a part of the html source code, and I want the eggdrop to post the red marked text on my channel when somebody types !test.

Thanks for helping!


p.s.
Here another good example:
http://uhrzeit.org/atomuhr.html
(uhrzeit is german and means "Time"; uhr = a clock)

When somebody types !time, I want that the time is posted on the channel.
The source code from the website:
Code:
...code...
<h6 id="anzeige" class="off" style="padding-left:15px;padding-right:15px;">

                     13:39:53</h6><br>
                  <br>
                  Die Uhrzeit wird in regelmässigen Abständen mit.....code.....




EDIT:
I tried the script from demond (which needs tDOC), and it works. But it only works in my shell at home:) not with the eggdrop


Last edited by karodde on Thu May 03, 2007 7:46 am; edited 1 time in total
Back to top
View user's profile Send private message
rosc2112
Revered One


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

PostPosted: Fri May 04, 2007 3:12 am    Post subject: Reply with quote

You want to use regexp to get the string you're looking for. From your example, something like:
Code:

regexp {<h6 id="anzeige".*?>(.*?)</h6>.*?Die Uhrzeit} $htmlInput fullmatch exactmatch

There's lots of example scripts for grabbing data from html pages. Take a look around the forum and archive.
Back to top
View user's profile Send private message
karodde
Voice


Joined: 01 May 2007
Posts: 10

PostPosted: Fri May 04, 2007 12:57 pm    Post subject: Reply with quote

Code:
bind pub - !example my:example

proc my:example {nick uhost hand chan text} {
  set url "http://uhrzeit.org/atomuhr.html"
  set token [::http::geturl $url]
  set content [::http::data $token]
  ::http::cleanup $content
  regexp {<h6 id="anzeige".*?>(.*?)</h6>.*?Die Uhrzeit} $content fullmatch exactmatch
  putserv "PRIVMSG $chan :$exactmatch"
}


The script doesnt work, but when I change the last line:

putserv "PRIVMSG $chan :$exactmatch"
to
putserv "PRIVMSG $chan :$fullmatch"

I get the following message from my eggdrop by typing !example

Quote:
(MyEggdrop) <h6 id="anzeige" class="off" style="padding-left:15px;padding-right:15px;">



p.s.
for other sites it works, thanks.
Back to top
View user's profile Send private message
karodde
Voice


Joined: 01 May 2007
Posts: 10

PostPosted: Fri May 04, 2007 1:58 pm    Post subject: Reply with quote

Code:
bind pub - !test my:test

proc my:test {nick uhost hand chan text} {          #this has to have the name theproc1
  set url "http://www.site.com/page.htm"
  set token [::http::geturl $url]
  set content [::http::data $token]
  ::http::cleanup $content
  regexp {<html>(.*?)</html>.*?} $content fullmatch exactmatch
  regexp {<html>(.*?)</html>.*?} $content fullmatch2 exactmatch2
  putserv "PRIVMSG $chan : $exactmatch"
}

When somebody types !test the 'proc' from my code will be outputted by eggdrop.

What I want now, is to give this 'proc' a name, so that I have to type "!test theproc1" to let the eggdrop output the proc theproc1.
I have other proc's too in the later code, I want to give each proc a name,
theproc1
theproc2
theproc3 and so on...

So is there any chance to give each 'proc' a name? I want that the command !test doesnt work, just the commands !test theproc1, !test theproc2, !test theproc3 should work.
Back to top
View user's profile Send private message
rosc2112
Revered One


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

PostPosted: Fri May 04, 2007 5:28 pm    Post subject: Reply with quote

There are newlines in the result, so you either need to remove them with regsub or do some further processing (perhaps using foreach line [split $exactmatch \n]) or even change the regexp to take account of the newlines.

As far as how to handle parameters within a single proc, you basically test for them and process them. A short example:

Code:

proc myproc {nick uhost hand chan text} {
        set command [lindex [split $text] 0]
        if {$command == "" || $command == "option1"} {
               # do thing1
        } elseif {$command == "option2"} {
               #do thing2
        } elseif {$command == "option3"} {
               #do thing3
        } else {
               #do default action
        }
#anti-wordwrap######################################


The action part of the if's (#do thing) can call another proc and return, or call another proc and wait for the result. If you want to get the result, you use like:
Code:

#do thing1
set myvar [someotherproc (optional parameters)]

where optional parameters can be input such as $command, $nick, $text, and so on, or whatever params you want to pass to "someotherproc"

If you just want to branch off to another proc, you do:
[code]
# do thing2
someotherproc (optional params)
return
[code]
Or you might want to do further processing after calling someotherproc so you leave the "return" out.

You can also integrate the other subprocs into the main proc, under the "if's"

Matter of style and design really. I generally keep everything in the same proc, unless it's reusable (meaning, other scripts or parts of the same script use the functions.) As an example, when I make html scripts, if I have to do extensive regsub's or word-wrapping, I make the wordwrap and regsub functions into seperate procs, so that there's only 1 copy of that processing code, instead of duplicating it under many different "if" sections of the main proc.

Hope that makes some sense.
Back to top
View user's profile Send private message
karodde
Voice


Joined: 01 May 2007
Posts: 10

PostPosted: Fri May 04, 2007 6:19 pm    Post subject: Reply with quote

thanks,
now I have a last question.

Quote:
bind pub - !hello my:test

proc my:test {nick uhost hand chan text} {
set url "http://www.site.com/$hello.htm"
set token [::http::geturl $url]
set content [::http::data $token]
::http::cleanup $content
regexp {<html>(.*?)</html>.*?} $content fullmatch exactmatch
regexp {<html>(.*?)</html>.*?} $content fullmatch2 exactmatch2
putserv "PRIVMSG $chan : $exactmatch"
}


I want that the ! command (in my case !hello) is set as a variable which stands for the .htm file.

For example:
Somebody types !chair, then the page http://www.site.com/chair.htm has to be proc'ed in my proc code.
When a word is typed, that not exists (at the site) then a error message has to came.
sorry for my english

that would be awsome, thanks for the help!
Back to top
View user's profile Send private message
karodde
Voice


Joined: 01 May 2007
Posts: 10

PostPosted: Fri May 04, 2007 9:13 pm    Post subject: Reply with quote

Another Way I would appreciate even more is this:
The command !hello is standard and should have 2 more attributes.
!hello chair blue, !hello table green and so on.
'chair blue' will have to link to a proc, 'table green' to another proc, table red to another proc, table white also to another etc...

How to make this?

I still need to tell the script, that chair has to link to chair.htm and table to table.htm. So I will have to make a variable of the .htm.
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 -> Scripting Help 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