Created
February 7, 2017 00:48
-
-
Save colomon/89a6e7b8bf7694aa42e83058bb43f489 to your computer and use it in GitHub Desktop.
This file contains 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
use v6; | |
use Inline::Python; | |
my $date = DateTime.now; | |
my %days-of-the-week := { | |
Monday => 1, | |
Tuesday => 2, | |
Wednesday => 3, | |
Thursday => 4, | |
Friday => 5, | |
Saturday => 6, | |
Sunday => 7 | |
}; | |
sub MAIN($task-file, :$test?) { | |
my $py = Inline::Python.new(); | |
$py.run(qq:heredoc/PYTHON/); | |
import wunderpy2 | |
api = wunderpy2.WunderApi() | |
PYTHON | |
my $api = $py.run('api', :eval); | |
my $client = $api.get_client("private info hidden", "private info hidden"); | |
my $lists = $client.get_lists(); | |
my %lists = $lists.map({ $_<title> => $_}); | |
sub task-days-latent($list-name, $task-name) { | |
my @tasks := $client.get_tasks(%lists{$list-name}<id>); | |
return 0 if @tasks.grep({ $_<title> eq $task-name }); | |
@tasks := $client.get_tasks(%lists{$list-name}<id>, completed => "True"); | |
DateTime.now.daycount - @tasks.grep({ $_<title> eq $task-name }).map({ DateTime.new($_<completed_at>).daycount }).max; | |
} | |
for $task-file.IO.lines() { | |
if /(\S+) \s+ (\S+) \s+ (.*)/ { | |
my $trigger = ~$0; | |
my $list = ~$1; | |
my $task = ~$2; | |
# dd $trigger; | |
# dd $list; | |
# dd $task; | |
my $fire = False; | |
given $trigger { | |
when /^(\d+)/ { | |
$fire = ($0 == $date.day-of-month); | |
} | |
when %days-of-the-week{$_}:exists { | |
$fire = (%days-of-the-week{$_} == $date.day-of-week); | |
} | |
when /^ "skip-" (\d+)/ { | |
$fire = ($0 <= task-days-latent($list, $task)); | |
} | |
} | |
if $fire { | |
say "Adding $task to $list"; | |
$client.create_task(%lists{$list}<id>, $task) unless $test; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example input data:
"skip-180" means add this to the to-do list 180 days after the last time it was completed. "10th" means on the 10th of the month. "Monday" means just what it says. The second column controls which Wunderlist list the item is added to.