Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 54 lines (41 sloc) 1.37 KB
#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
use autodie qw(:all);
use WWW::Mechanize;
use Config::Tiny;
use JSON::Any;
use AnyDBM_File;
use WebService::Beeminder;
use POSIX qw(O_CREAT O_RDWR);
use constant DANCE_STUDIO => "First Floor 393";
use constant DEBUG => $ENV{DEBUG} || 0;
my $config = Config::Tiny->read("$ENV{HOME}/.rtbmrc");
my $TOKEN = "oauth_token=$config->{FourSquare}{auth_token}&v=20121108";
my $BASE = 'https://api.foursquare.com/v2';
my $mech = WWW::Mechanize->new();
my $json = JSON::Any->new;
my $bee = WebService::Beeminder->new(
token => $config->{Beeminder}{auth_token},
);
my %seen;
tie %seen, 'AnyDBM_File', "$ENV{HOME}/.beesquare.seen", O_CREAT|O_RDWR, 0666;
$mech->get("$BASE/users/self/checkins?$TOKEN");
my $checkins = $json->decode($mech->content)->{response}{checkins}{items};
foreach my $checkin (@$checkins) {
say "$checkin->{id} $checkin->{venue}{name}" if DEBUG;
# Skip entries we've already scored points for
next if $seen{$checkin->{id}};
# TODO: These should all be in a config file, but my tram
# ride is about to end.
if ($checkin->{venue}{name} eq DANCE_STUDIO) {
say "Adding points for $checkin->{venue}{name}" if DEBUG;
$bee->add_datapoint(
goal => 'dance',
value => 1,
comment => 'auto: beesquare'
);
$seen{$checkin->{id}} = 1;
}
}