12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #!/usr/bin/perl -w
- # Usage: ./irpg.pl <playername1> <playername2> ...
- use strict;
- use LWP::Simple;
- use POSIX qw(strftime);
- die "Usage: $0 <playernames>\n" .
- "Example: $0 playera playerb\n" if @ARGV == 0;
- my $time = strftime "%Y-%m-%d %H:%M:%S %Z", localtime;
- my $page = get "http://xethron.lolhosting.net/players.php";
- my @lines = split("\n", $page);
- start:
- my $username = shift(@ARGV);
- my $rank = 0;
- # Only line is commented if there is no such user
- my $line = "";
- foreach my $l (@lines) {
- if($l =~ /playerview.php\?player=/) {
- $rank++;
- }
- if($l !~ /\>$username\<\/a\>, the level/) {
- next;
- }
- $line = $l;
- last;
- }
- if ($line eq "") {
- print "user=$username error='No such player'\n";
- } else {
- # We have a line for a user
- # Examples:
- # <li><a href="playerview.php?player=shandor">shandor</a>, the level 75 "the active". Next level in 41 days, 18:09:46.</li>
- # <li><a href="playerview.php?player=SirMonkeybox">SirMonkeybox</a>, the level 77 GarlicSlayer. Next level in 48 days, 01:42:33.</li>
- chomp $line;
- # Offline players have a CSS class
- my $status = ($line =~ /class="offline"/) ? "offline" : "online";
-
- # Level is self explanatory
- my $level = "n/a";
- my $class = "n/a";
- if($line =~ /, the level ([0-9]+) ([^\.]+)./) {
- $level = $1;
- $class = $2;
- }
- my ($ttl, $ttl_days, $ttl_hours, $ttl_mins, $ttl_secs);
- if($line =~ /Next level in ([0-9]+) days?, ([0-9]{2}):([0-9]{2}):([0-9]{2})./) {
- $ttl_days = $1;
- $ttl_hours = $2;
- $ttl_mins = $3;
- $ttl_secs = $4;
- $ttl = $ttl_days * 24 * 60 * 60
- + $ttl_hours * 60 * 60
- + $ttl_mins * 60
- + $ttl_secs;
- } else {
- $ttl = "undef";
- }
- print "$time user=$username class=\"$class\" status=$status level=$level ttl=$ttl rank=$rank";
- print "\n";
- }
- goto start if @ARGV != 0;
|