パルカワ2

PerlとRubyとイチャラブ

ガツガツ系リマインダー

という名前で昔作っていた。ウケる。
15分に一回回すみたいなのやってて、30分くらいで使うのやめました。

まだ動くかわかりません。

use 5.10.1;
use strict;
use warnings;
use utf8;
use WebService::RTMAgent;
use Cocoa::Growl ':all';
use Encode qw(encode_utf8);

my $API_KEY    = '';
my $API_SECRET = '';
my $GROWL_ICON = '';

growl_register(
    app           => "ガツガツ系リマインダー - さっさとやれ",
    notifications => ['remind'],
);

main();

sub main {
    my $res = request('filter=status:incomplete AND due:today');
    my $tasks = $res->{tasks};

    for my $task (@$tasks) {
        my $list = $task->{list} or next;

        for my $todo (@$list) {
            my $taskseries = $todo->{taskseries} or next;

            for my $series (@$taskseries) {
                my $title = $series->{notes}->[0]->{note}->[0]->{content} || 'さっさとやれ';
                growl($title => $series->{name});
            }
        }
    }
}

sub request {
    my (@filter) = @_;
    my $ua = rtm_ua();
    my $url = $ua->get_auth_url or die "cannot get auth url.";
    my $res = $ua->tasks_getList(@filter) or die "auth url: $url";

    return $res;
}

sub growl {
    my ($title, $description) = @_;
    growl_notify(
        name        => 'remind',
        title       => encode_utf8($title),
        description => encode_utf8($description),
        icon        => $GROWL_ICON,
    );
}

sub rtm_ua {
    state $ua = do {
        my $ua = WebService::RTMAgent->new;
        $ua->api_key($API_KEY);
        $ua->api_secret($API_SECRET);
        $ua->init;
        $ua;
    };
    return $ua;
}