dirkobot/getplayers.pl
2011-08-02 22:55:28 -04:00

41 lines
985 B
Perl
Executable file

#!/usr/bin/perl
use strict;
use warnings;
use autodie;
use LWP::UserAgent;
use JSON::XS;
use POSIX qw/strftime/;
use Data::Dumper;
# TODO this might need to change if dynmap fixes their json
our $world_url = "http://map.dirkocraft.com/up/world/main/";
our $playerstate = {}; # keep these global! is something funny happenign with the modules?
my $ua = LWP::UserAgent->new();
my $crash = 0;
my $ls = 0;
sub get_player_pos {
my ($user) = @_;
my $resp = $ua->get($world_url); # get the json for the server
if ($resp->is_success()) {
$ls = 1;
my $cont = $resp->content();
open(my $fh, ">", "positions/players-".strftime("%FT%T", localtime()).".json");
print $fh "/*".$resp->code()." ".$resp->message() . "*/";
print $fh $cont;
print "SUCCESS $ls $crash /*".$resp->code()." ".$resp->message() . "*/\n";
close($fh);
} else {
print "CRASH $ls $crash\n";
$crash++ if ($ls == 1);
$ls = 0;
}
}
while(1) {get_player_pos(); sleep 30};