#!/usr/bin/perl -w # Usage: ./irpg.pl ... use strict; use LWP::Simple; use POSIX qw(strftime); die "Usage: $0 \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: #
  • shandor, the level 75 "the active". Next level in 41 days, 18:09:46.
  • #
  • SirMonkeybox, the level 77 GarlicSlayer. Next level in 48 days, 01:42:33.
  • 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;