Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/perl -w
use 5.010;
use strict;
use warnings;
use autodie qw( :all );
use WebService::Beeminder;
use Config::Tiny;
# use Smart::Comments;
# Get our beeminder auth token.
my $config = Config::Tiny->read("$ENV{HOME}/.rtbmrc");
$config or die "Can't read ~/.rtbmrc config file";
my $token = $config->{Beeminder}{auth_token};
my $bee = WebService::Beeminder->new( token => $token );
my $goals = $bee->user(
skinny => 1, goals_filter => 'frontburner', diff_since=>1,
)->{goals};
my $now = time();
foreach my $goal (sort { $a->{losedate} <=> $b->{losedate} } @$goals) {
my $timeleft = timeleft($goal->{losedate} - $now);
say "[$timeleft] $goal->{slug}";
}
sub timeleft {
my ($sec) = @_;
my $days = int($sec / 86400);
my $hrs = int( ($sec - ($days * 86400))/3600);
return "${days}d ${hrs}hrs";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment