Skip to content

Instantly share code, notes, and snippets.

@jshirley
Created August 22, 2013 21:05
Show Gist options
  • Save jshirley/6312764 to your computer and use it in GitHub Desktop.
Save jshirley/6312764 to your computer and use it in GitHub Desktop.
Parse the TDP v1 /goals API result to find cooldown goals "expiration" date
#!env perl
use JSON;
use DateTimeX::Easy;
use Data::Printer;
my $json = JSON::decode_json(<STDIN>);
my $goals = $json->{goals};
die "Bad input!" unless $goals and ref $goals eq 'ARRAY';
foreach my $goal ( @$goals ) {
next unless $goal->{cooldown} > 1;
my @actual_days = grep { defined $_->{id} } @{ $goal->{trend} || [] };
if ( @actual_days ) {
my $day = DateTimeX::Easy->parse($actual_days[-1]->{date});
print "$goal->{name} goes pear shaped on " . $day->add( days => $goal->{cooldown} ) . "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment