Created
August 15, 2012 05:53
-
-
Save pjf/3356632 to your computer and use it in GitHub Desktop.
bmndr code
This file contains hidden or 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
#!/usr/bin/perl -w | |
use 5.010; | |
use strict; | |
use warnings; | |
use autodie qw( :all ); | |
use POSIX qw( strftime ); | |
use Config::Tiny; | |
use WWW::Mechanize; | |
use JSON::Any; | |
my ($goal, $datapoint, $comment) = @ARGV; | |
unless ($datapoint =~ /^\d+$/) { | |
die "Usage: $0 goal datapoint [comment]\n"; | |
} | |
# Get our beeminder auth token. | |
my $config = Config::Tiny->read("$ENV{HOME}/.rtbmrc"); | |
$config or die "Can't read ~/.rtbmrc config file"; | |
my $auth_token = $config->{Beeminder}{auth_token}; | |
# User agent time. | |
my $mech = WWW::Mechanize->new( | |
autocheck => 1, | |
); | |
$comment ||= "Auto-submitted from pjf/bmndr"; | |
$comment =~ s/"//g; # Strip quotes | |
$mech->post( | |
"http://beeminder.com/api/v1/users/pjf/goals/$goal/datapoints.json?auth_token=$auth_token", | |
{ | |
timestamp => time(), | |
value => $datapoint, | |
comment => $comment | |
} | |
); | |
# say $mech->content; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment