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.

ServerCheck script

Old posts that have not been replied to for several years.
Locked
c
cvanmeer
Halfop
Posts: 40
Joined: Tue Dec 02, 2003 1:00 pm
Location: The Netherlands
Contact:

ServerCheck script

Post by cvanmeer »

Hi,

I'm stuck with creating a TCL script. I have a webpage that I get with http::geturl etc. the output of that file is in $data

let's say the content of $data is:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <body>
      <div id="maindiv" >
      <div id="ServerCheckDiv">
    <table id="ServerCheckTable">
      <tr><th>Server</th><th>Status</th><tr>
      <tr><td>Account</td><td><img SRC="dot_green.gif"/>Online</td></tr>
      <tr><td>Character</td><td><img SRC="dot_green.gif"/>Online</td></tr>

      <tr><td>Interact</td><td><img SRC="dot_green.gif"/>Online</td></tr>
      <tr><td>Zone</td><td><img SRC="dot_green.gif"/>Online</td></tr>
      <tr><td>Proxy</td><td><img SRC="dot_green.gif"/>Online</td></tr>
    </table>
</div>
</div>
  </body>
</html>
In this file you see 5 types of servers: Account, Character, Interact, Zone and Proxy. Behind that is says if it's on- or offline

Now I want to make a script that will retrieve every server status and post it on the chan (the account server status goes to $account, character status goes to $character, etc.)

So I want to parse the file and select only row nrs. 8 till 13.
Then it has to search in those rows of it says ONLINE or OFFLINE
And than put that in the right variable (account status in $account, etc)

Could someone help me? I'm really stuck...been trying to make this for over a month now

thx.

Chris
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Try the method provided in this thread with the following regexp rule:

Code: Select all

{<tr><td>([^<]+)</td><td><img [^>]+>([^<]+)</td></tr>}
This will make it fairly robust I hope. Clue: the first variable in the foreach will be overwritten by the second one by the same name (making it discard the first reported value in each match, which is the entire match)
Have you ever read "The Manual"?
c
cvanmeer
Halfop
Posts: 40
Joined: Tue Dec 02, 2003 1:00 pm
Location: The Netherlands
Contact:

Post by cvanmeer »

This will make it fairly robust I hope. Clue: the first variable in the foreach will be overwritten by the second one by the same name (making it discard the first reported value in each match, which is the entire match)
I don't get it, sorry.

And how do I put the right values in the right one of the 5 variables?

could you write some code to help me?

thx.

Chris
PS. Sorry I don't understand what you mean. I'm not that an expert :(
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Did you check the thread i refered to? I'd use an array (in case they add new values, so you don't risk overwriting existing variables)...or create the output directly in the foreach...
example 1 (creating the a string for output):

Code: Select all

set out {}
foreach {server server status} [regexp -all -nocase -inline {<tr><td>([^<]+)</td><td><img [^>]+>([^<]+)</td></tr>} $html] {
	lappend out "$server is $status"
}
set out [join $out ", "]
example 2 (storing the values in an array):

Code: Select all

foreach {server server status} [regexp -all -nocase -inline {<tr><td>([^<]+)</td><td><img [^>]+>([^<]+)</td></tr>} $html] {
	set onoroff($server) $status
}
..then loop through [array names onoroff] or access onoroff(Name) directly (check if {[info exists ...] first to avoid errors)
Have you ever read "The Manual"?
c
cvanmeer
Halfop
Posts: 40
Joined: Tue Dec 02, 2003 1:00 pm
Location: The Netherlands
Contact:

Post by cvanmeer »

thank you!
it worked
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

The cut'n'paste-force is strong with this one

Post by user »

cvanmeer wrote:it worked
Cool :mrgreen:
Have you ever read "The Manual"?
Locked