irpg.pl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/perl -w
  2. # Usage: ./irpg.pl <playername1> <playername2> ...
  3. use strict;
  4. use LWP::Simple;
  5. use POSIX qw(strftime);
  6. die "Usage: $0 <playernames>\n" .
  7. "Example: $0 playera playerb\n" if @ARGV == 0;
  8. my $time = strftime "%Y-%m-%d %H:%M:%S %Z", localtime;
  9. my $page = get "http://xethron.lolhosting.net/players.php";
  10. my @lines = split("\n", $page);
  11. start:
  12. my $username = shift(@ARGV);
  13. my $rank = 0;
  14. # Only line is commented if there is no such user
  15. my $line = "";
  16. foreach my $l (@lines) {
  17. if($l =~ /playerview.php\?player=/) {
  18. $rank++;
  19. }
  20. if($l !~ /\>$username\<\/a\>, the level/) {
  21. next;
  22. }
  23. $line = $l;
  24. last;
  25. }
  26. if ($line eq "") {
  27. print "user=$username error='No such player'\n";
  28. } else {
  29. # We have a line for a user
  30. # Examples:
  31. # <li><a href="playerview.php?player=shandor">shandor</a>, the level 75 &quot;the active&quot;. Next level in 41 days, 18:09:46.</li>
  32. # <li><a href="playerview.php?player=SirMonkeybox">SirMonkeybox</a>, the level 77 GarlicSlayer. Next level in 48 days, 01:42:33.</li>
  33. chomp $line;
  34. # Offline players have a CSS class
  35. my $status = ($line =~ /class="offline"/) ? "offline" : "online";
  36. # Level is self explanatory
  37. my $level = "n/a";
  38. my $class = "n/a";
  39. if($line =~ /, the level ([0-9]+) ([^\.]+)./) {
  40. $level = $1;
  41. $class = $2;
  42. }
  43. my ($ttl, $ttl_days, $ttl_hours, $ttl_mins, $ttl_secs);
  44. if($line =~ /Next level in ([0-9]+) days?, ([0-9]{2}):([0-9]{2}):([0-9]{2})./) {
  45. $ttl_days = $1;
  46. $ttl_hours = $2;
  47. $ttl_mins = $3;
  48. $ttl_secs = $4;
  49. $ttl = $ttl_days * 24 * 60 * 60
  50. + $ttl_hours * 60 * 60
  51. + $ttl_mins * 60
  52. + $ttl_secs;
  53. } else {
  54. $ttl = "undef";
  55. }
  56. print "$time user=$username class=\"$class\" status=$status level=$level ttl=$ttl rank=$rank";
  57. print "\n";
  58. }
  59. goto start if @ARGV != 0;