Created
March 7, 2012 22:00
-
-
Save larsen/1996500 to your computer and use it in GitHub Desktop.
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
| use strict; | |
| use warnings; | |
| use feature qw/ say /; | |
| use constant MXM_HM_GROUP => 9604; | |
| use Net::Hiveminder; | |
| use DateTime; | |
| our $CONFFILE = "$ENV{HOME}/.hiveminder"; | |
| my $hm = Net::Hiveminder->new(use_config => 1, config_file => $CONFFILE); | |
| my @tasks = $hm->get_tasks( | |
| complete_not => 1, | |
| group => MXM_HM_GROUP | |
| ); | |
| say "Tasks fetched."; | |
| foreach my $t ( sort with_due_date_first @tasks ) { | |
| next if due_after_next_week( $t ); | |
| print_task( $t ); | |
| } | |
| sub print_task { | |
| my $task = shift; | |
| say "- $task->{ summary } " | |
| . (defined $task->{ owner } ? ("[" . owner_email( $task->{ owner } ) . "]") : "") | |
| . (defined $task->{ due } ? "[Due: $task->{ due }]" : ""); | |
| } | |
| { | |
| my $emails_cache; | |
| sub owner_email { | |
| my $id = shift; | |
| if ( not exists $emails_cache->{ $id } ) { | |
| $emails_cache->{ $id } = $hm->email_of( $id ); | |
| } | |
| return $emails_cache->{ $id }; | |
| } | |
| } | |
| sub hm2datetime { | |
| my $date = shift; | |
| my ( $year, $month, $day ); | |
| if ( $date =~ /(\d{4})-(\d{2})-(\d{2})/ ) { | |
| return DateTime->new( | |
| year => $1, | |
| month => $2, | |
| day => $3 | |
| ); | |
| } | |
| } | |
| { | |
| my $next_week = DateTime->now->add( days => 7 ); | |
| sub due_after_next_week { | |
| my $task; | |
| return unless $task->{ due }; | |
| my $task_due_date = hm2datetime( $task->{ due } ); | |
| return unless $task_due_date; | |
| return $task_due_date > $next_week; | |
| } | |
| } | |
| sub with_due_date_first { | |
| return 0 if defined $a->{ due } and defined $b->{ due }; | |
| return -1 if defined $a->{ due }; | |
| return 1 if defined $b->{ due }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment