Created
August 22, 2013 21:05
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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