-
Notifications
You must be signed in to change notification settings - Fork 9
/
tdp-score
executable file
·53 lines (40 loc) · 1.18 KB
/
tdp-score
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/home/rjbs/perl5/perlbrew/perls/16.0/bin/perl
use 5.16.0;
use warnings;
use DateTime;
use DBI;
use Getopt::Long::Descriptive;
use JSON ();
use LWP::UserAgent;
use LWP::Simple qw(get);
my $MAX = 21;
my $res = LWP::UserAgent->new->get(
"http://tdp.me/v1/goals/?range=$MAX,1",
'Content-type' => 'application/json',
'X-Access-Token' => $ENV{TDP_TOKEN},
);
die "GOAL GET FAIL: " . $res->as_string unless $res->is_success;
my $json = $res->decoded_content;
my $data = JSON->new->decode($json);
my $today = DateTime->today->format_cldr('yyyy-MM-dd');
my %score = map {; $_ => 0 } qw(yesterday today);
use constant {
TODAY => -2,
YESTERDAY => -3,
VORGESTERN => -4,
};
for my $goal (grep { $_->{active} } @{ $data->{goals} }) {
my $y = $goal->{trend}[ VORGESTERN ]{streak} // 0;
my $t = $goal->{trend}[ YESTERDAY ]{streak} // 0;
warn "TODAY IS NOT TODAY!!" unless $goal->{trend}[TODAY]{today};
print "$goal->{name}\n $y -> $t\n";
if ($t - $y > 1) {
use Data::Dumper;
warn "Score went up more than one in a day??";
warn Dumper($goal);
}
$score{yesterday} += $y;
$score{today } += $t;
}
say "Yesterday: $score{yesterday}";
say "Today : $score{today}";