Various improvements so that TODO's scheduled for current day appear.

This commit is contained in:
Bradley M. Kuhn 2013-09-03 10:44:47 -04:00
parent e6a901057f
commit 46edc5c63f

View file

@ -36,7 +36,7 @@ if ($? != 0) {
exit 0; exit 0;
} }
my $now = ParseDate("now"); my $now = ParseDate("now");
open(ORG_MODE_AGENDA, "-|", "/usr/bin/emacs -batch -l ~/.emacs -eval '(org-batch-agenda \"a\" org-agenda-files (mapcar (lambda (arg) (replace-regexp-in-string \"~/Crypt/Orgs/\" \"~/Crypt/.org-backup/\" arg)) org-agenda-files) org-agenda-span (quote 10) org-agenda-overriding-header \"\" org-agenda-repeating-timestamp-show-all t org-agenda-time-grid nil org-agenda-repeating-timestamp-show-all t org-agenda-entry-types (quote (:sexp :scheduled))))' 2>/dev/null") or open(ORG_MODE_AGENDA, "-|", "/usr/bin/emacs -batch -l ~/.emacs -eval '(org-batch-agenda \"a\" org-agenda-files (mapcar (lambda (arg) (replace-regexp-in-string \"~/Crypt/Orgs/\" \"~/Crypt/.org-backup/\" arg)) org-agenda-files) org-agenda-span (quote 10) org-agenda-overriding-header \"\" org-agenda-repeating-timestamp-show-all t org-agenda-time-grid nil org-agenda-repeating-timestamp-show-all t org-agenda-entry-types (quote (:sexp :scheduled)))' 2>/dev/null") or
die "Unable to run emacs: $!"; die "Unable to run emacs: $!";
my $firstDay; my $firstDay;
@ -52,40 +52,61 @@ while (my $line = <ORG_MODE_AGENDA>) {
$dayLine =~ s/\s*W\d+\s*$//; $dayLine =~ s/\s*W\d+\s*$//;
$prettyDayLine = "\${color3}$dayLine\${color}\n"; $prettyDayLine = "\${color3}$dayLine\${color}\n";
} }
elsif ($line =~ /^\s+([^:]+)\s*:\s+(\d+)\s*:\s*(\d+)\s*[\-\.]+(?:\s*(\d+)\s*:\s*(\d+))?(.*)$/) { elsif ($line =~ /^\s+([^:]+)\s*:\s*(\d+)\s*:\s*(\d+)\s*[\-\.]+(?:\s*(\d+)\s*:\s*(\d+))?(.*)$/) {
my($source, $startHour, $startMin, $endHour, $endMin, $rest) = my($source, $startHour, $startMin, $endHour, $endMin, $rest) =
($1, $2, $3, $4, $5, $6); ($1, $2, $3, $4, $5, $6);
my $start = "$startHour:$startMin"; next if $rest =~ /Sched.*\d+x\s*:/; # Skip overdue TODOs, because I have lot.
my $end = "$endHour:$endMin"; my $type;
my $date = ParseDate("$dayLine $start"); if ($rest =~ s/^\s*Scheduled?\s*:\s*(WAITING|TODO|APPT|DELEGATED|DONE|DEFFERRED|CANCELLED|STARTED)\s*//i) {
my $endDate = ParseDate("$dayLine $end"); $type = $1;
$endDate = DateCalc($date, "+ 1 hour") unless defined $endDate; } else {
$thisLinePrintable = " $start-$end $rest\${alignr 10}(from $source)" $type = $source;
unless $endDate lt $now; }
# At this point, we'd hope we'd hit a "\S+" line, which would indicate $startHour = "0$startHour" if length($startHour) == 1;
# that there's a date in this output, as they start at column 0 on the my $start = "$startHour:$startMin";
# output. However, if we happen to find something odd in the output, my $date = ParseDate("$dayLine $start");
# just treat it like an Appointment without a known date. my($endDate, $end);
if (not defined $firstDay) { if (not defined $endHour) {
print "Appointment, on an Unknown Date:\n" $endDate = DateCalc($date, "+ 8 hour");
if $thisLinePrintable; $end = "";
} elsif ($firstDay) { } else {
my $val = $3; $endMin = "00" if (not defined $endMin);
if (DateCalc("$now", "+ 15 minutes") ge $date and $now le $date) { $end = "$endHour:$endMin";
my $fh = File::Temp->new(); $endDate = ParseDate("$dayLine $end");
$fh->unlink_on_destroy( 1 ); $end = "-$end";
my $fname = $fh->filename; }
print $fh "You have an appointment at $start: $rest\n"; # Diaries and appointments are always printed, and have notifier.
$fh->close(); if ($source =~ /(Diary|APPT)/i or $type =~ /(Diary|APPT)/i) {
system('/home/bkuhn/bin/myosd', $fname); $thisLinePrintable = " $start$end $rest\${alignr 10} (from $source)"
system("/usr/bin/espeak", '-p', '45', '-s', '130', '-f', $fname) if ($endDate gt $now);
unless -f "$ENV{HOME}/.silent-running"; # At this point, we'd hope we'd hit a "\S+" line, which would indicate
system('/usr/bin/notify-send', '-u', 'critical', '-t', '300000', # that there's a date in this output, as they start at column 0 on the
'Appointment', "You have an appointment at $start: $rest"); # output. However, if we happen to find something odd in the output,
} # just treat it like an Appointment without a known date.
if (not defined $firstDay) {
print "Appointment, on an Unknown Date:\n"
if $thisLinePrintable;
} elsif ($firstDay) {
my $val = $3;
if (DateCalc("$now", "+ 15 minutes") ge $date and $now le $date) {
my $fh = File::Temp->new();
$fh->unlink_on_destroy( 1 );
my $fname = $fh->filename;
print $fh "You have an appointment at $start: $rest\n";
$fh->close();
system('/home/bkuhn/bin/myosd', $fname);
system("/usr/bin/espeak", '-p', '45', '-s', '130', '-f', $fname)
unless -f "$ENV{HOME}/.silent-running";
system('/usr/bin/notify-send', '-u', 'critical', '-t', '300000',
'Appointment', "You have an appointment at $start: $rest");
}
}
} else { # Source isn't a diary or appointment
$thisLinePrintable = " $start$end $rest\${alignr 10}(from $source)"
if (($endDate gt $now) and
($firstDay or $type =~ /(birthday|anniversary)/i
or $source =~ /(birthday|anniversary)/i));
} }
} elsif ($line =~ /^\s+(?:birthday|anniversary)\s*:\s*(\S.+)\s*$/i) {
$thisLinePrintable = " $1";
} }
if (defined $thisLinePrintable) { if (defined $thisLinePrintable) {
if (defined $prettyDayLine) { if (defined $prettyDayLine) {