Forums » General

a new script

Feb 26, 2004 red cactus link
Hey guys, I just finished making a Perl script. Now, what this Perl script does is: goes to the active players page on this site, parses it, and then displays all of the active players and their nations. Unforunately, this is for Linux users only, as it's a command line program, and uses Lynx to get the source. It could be for OS X, but I don't know whether you'd have to install Lynx. I could most likely write a Windows version using a module, but then in order for the user to USE it, s/he'd have to go through all that mess of installing Perl, and then the module. The other option is for me to put this up on my website (or give it to Roguelazer and put it on his website), which would eliminate all compatitibility issues. But, if I was to put it on my website, you could just as easily visit the REAL page on THIS site. Hmm.

Here's the script (I think me posting this will eliminate all spacing, but it'll parse the same):
vplayers:

#!/usr/bin/perl


# Description: Checks the Vendetta website and prints back the currently online players
# Author: Tyler Denniston (Vendetta character name: red cactus)
# Contact: tyler@forkandspoonsw.com OR tdennist@earthlink.net
# Date started: 2/26/04
# Date finished: 2/26/04 (two hours later...)

@lines=split(/\n/,`lynx -source http://vendetta.guildsoftware.com/?action=active`);
$trtag='<tr>';
$endtrtag='</tr>';

while ($count <= 52) {
$count++;
shift @lines; #get rid of the first 17 lines; we don't need them
}
$count=0;
while ($count <= 8) {
$count++;
pop @lines; #get rid of the last 15 lines; we don't need them
}

$totals=$lines[-1]; #the line that says how many blues, golds, reds are online
pop @lines; #now get rid of it
#at this point, the only lines that are left in the array are the lines like this:
#IRC Blue 2004-02-25 21:12:49 0 0 0 0
#name nation last login score bounty kills deaths
#we will only be taking the player name, and the nation to display. the rest of the information
#we will throw away
$count=0;
%hash = ();
print "Name Nation\n";
foreach $line (@lines) {
if ($line =~ /$trtag/) {
# Here's the meat of the parsing...it's a bit ugly, but it works!
$good1=$lines[$count+1];
$good2=$lines[$count+2];
$count++;
@temp=split(/">/,$good1);
@temp1=split(/<\//,$temp[1]);
$name=$temp1[0];
@temp=();
@temp1=();
@temp=split(/">/,$good2);
@temp1=split(/<\/font/,$temp[2]);
$nation=$temp1[0];
#pad with spaces the name for ease of display
$len=length($name);
if ($len<=29) {
$padlen=29-$len;
for ($i=1; $i<=$padlen;$i++){
$name =~ s/(.*)/\1 /;
}
}
$hash{$name} = $nation;
@temp=();
@temp1=();
next;
}
$count++;
}
foreach $item (sort keys %hash) {
print "$item$hash{$item}\n";
}
print "$totals\n";
@lines=();
Feb 26, 2004 red cactus link
Forgot to mention, in order to find a specific user, just pipe it through grep:

$ ./vplayers | grep "red cactus"

Or some such like that. Also, if you want a copy with proper spacing, email me at tdennist@earthlink.net and I'll get you one.

Feel free to make changes, and post 'em here. I'm all about open source...:-) And if anyone feels a strong urge to comment that extensively for me, go right ahead. :p

-rc
Feb 26, 2004 stick link
Nice... I have a much more simple python one but, your not gonna see it :P
Feb 26, 2004 red cactus link
...ok...
Feb 26, 2004 roguelazer link
I have a better bash one. Uses the html2 program, which is cross-platform (but rare). Most of it was stolen from cale.
Feb 26, 2004 red cactus link
Well, rogue, post it here, then! Let the people decide which they want to use. Because you use Linux, I would assume you're not against open source...:p

-rc
Feb 26, 2004 Arolte link
Is this something that would work with Konfabulator?
Feb 26, 2004 Hoax link
The biggest road block to Konfabulator is its desire for XML. The output of this script would likely be more easily parsed into XML style holding than the raw webpage but is still a step away from going straight into a Konfabulator widget. Really Konfabulator just needs to do some parsing much like this script only its limmited to JS with reg expressions.

What would be cool is if someone wrote some perl/php/whatever that converted the guild pages to xml. That would open a whole host of easy ways to play with the data presented.

Or, does anyone have some nice reg expressions written already for parsing the active players page?
Feb 26, 2004 roguelazer link
Mine could output to html if I wanted to add a couple of entries, does that count?

As for posting mine, well, I gotta find it first. Apache confused me because I accidentially overwrote my httpd.conf file...
Feb 26, 2004 panic link
Couldn't you use wget or curl instead?
Feb 26, 2004 roguelazer link
wget -q -O- http://vendetta.guildsoftware.com?action=active | html2 2>/dev/null | grep "/html/body/center/table/tr/td/font/table/tr/td\(/font\) *=" | cut -f2 -d=

wget -q -O- http://vendetta.guildsoftware.com?action=active | html2 2> /dev/null | grep "players --" | cut -d= -f2
Feb 26, 2004 red cactus link
If anyone can point me to a general XML syntax page, I can probably fix it...but I don't know.

-rc
Feb 26, 2004 paedric link
Sounds like something BusMasteR GT came out with about a year ago. It worked with Windows. And yes, it did use pearl.

Exerps from the README:
"* What is VS...

VS is a script that provides some functions for the game
Vendetta (by Guildsoftware). At the moment it features ingame
view of both the active players listing from vendetta's website,
and kills/deaths stats (kept locally, no support for vendetta's
stats), divided into PL, NPC, NPCDEF and caps/steals."
Feb 27, 2004 Durgia link
does not IRC bot do this if you /msg it?
Feb 27, 2004 red cactus link
Yes, but see the whole idea of th(ese|is) script(s) is that you don't have to be ingame to view who's online.

-rc
Feb 27, 2004 Durgia link
if you are not ingame look at the webpage
Feb 27, 2004 RelayeR link
Even if you are in-game, look at the web page.

Go to video settings, change to window mode and oped browser to the active players list. Check it at your leisure. You don't like window mode? Change back to full screen...total time from game...<1 min.