Forums » General
a new script
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=();
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=();
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
$ ./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
Nice... I have a much more simple python one but, your not gonna see it :P
...ok...
I have a better bash one. Uses the html2 program, which is cross-platform (but rare). Most of it was stolen from cale.
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
-rc
Is this something that would work with Konfabulator?
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?
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?
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...
As for posting mine, well, I gotta find it first. Apache confused me because I accidentially overwrote my httpd.conf file...
Couldn't you use wget or curl instead?
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
wget -q -O- http://vendetta.guildsoftware.com?action=active | html2 2> /dev/null | grep "players --" | cut -d= -f2
If anyone can point me to a general XML syntax page, I can probably fix it...but I don't know.
-rc
-rc
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."
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."
does not IRC bot do this if you /msg it?
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
-rc
if you are not ingame look at the webpage
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.
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.