diff options
author | Matthew Lemon <y@yulqen.org> | 2023-08-14 15:41:45 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2023-08-14 15:41:45 +0100 |
commit | a164aafde81e9bfdc548d2fa57b3f73194d99f87 (patch) | |
tree | 39b95cd9f0cb15f6ad0de1be305fc2c3e5d50914 | |
parent | a359ee02e20408043617b9a0c30ae7d9386916c2 (diff) | |
parent | 34af3f14728ef5a3565cd2f6fec46d6bf9c3a20f (diff) |
Merge branch 'master' of github.com:yulqen/perlscripts
-rw-r--r-- | annex_discovery.pl | 14 | ||||
-rwxr-xr-x | calendar/dayplan.pl | 6 | ||||
-rwxr-xr-x | calendar/dayplan_revised.pl | 2 | ||||
-rw-r--r-- | rename-journal-files.pl | 13 | ||||
-rwxr-xr-x | task_report_to_email.pl | 56 |
5 files changed, 89 insertions, 2 deletions
diff --git a/annex_discovery.pl b/annex_discovery.pl new file mode 100644 index 0000000..b645dc6 --- /dev/null +++ b/annex_discovery.pl @@ -0,0 +1,14 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use feature q(say); + +open my $fh, "<", "/home/lemon/Documents/find_these_paths.txt" or die "Cannot open file"; +while (<$fh>) { + if ($_ =~ q[^/home/lemon/annex/(.*) \(1 copy\)]) { + my $path = quotemeta($1); + my $out = `git annex whereis $path`; + say $out; + } +} diff --git a/calendar/dayplan.pl b/calendar/dayplan.pl index 3074c2d..3de906a 100755 --- a/calendar/dayplan.pl +++ b/calendar/dayplan.pl @@ -59,7 +59,7 @@ sub schoollines { return " 08:15 - 08:20 - Harvey to school 08:45 - 09:00 - Sophie to school -09:15 - 09:30 - Email"; +"; } } @@ -88,6 +88,10 @@ Reminders: --------- $reminders $s +Implementation Intentions: + +- I will X at HH:MM. + 09:30 - 10:00 - 10:00 - 11:00 - 11:00 - 12:00 - diff --git a/calendar/dayplan_revised.pl b/calendar/dayplan_revised.pl index 6e1ea07..862b191 100755 --- a/calendar/dayplan_revised.pl +++ b/calendar/dayplan_revised.pl @@ -1,4 +1,4 @@ -#!/usr/bin/env perl +#!/usr/bin/env -S perl # Porting dayplan.ksh to Perl use strict; diff --git a/rename-journal-files.pl b/rename-journal-files.pl new file mode 100644 index 0000000..24dc712 --- /dev/null +++ b/rename-journal-files.pl @@ -0,0 +1,13 @@ +#!/usr/bin/env perl + +opendir(DIR, ".") || die "Can't open directory: $!\n"; + +while (my $file = readdir(DIR)) { + if ($file =~ /(\d{4})_(\d{2})_(\d{2})\.md$/) { + my $new_name = "$1-$2-$3.md"; + rename($file, $new_name) || die "Can't rename file '$file': $!\n"; + } +} + +closedir(DIR); + diff --git a/task_report_to_email.pl b/task_report_to_email.pl new file mode 100755 index 0000000..f1260ed --- /dev/null +++ b/task_report_to_email.pl @@ -0,0 +1,56 @@ +#!/usr/bin/perl +use strict; +use warnings; + +use JSON; +use DateTime::Format::ISO8601; +use IPC::Open2; + +# written in collaboration with GPT-4 on 2023-05-03. +# This script takes the output of the taskwarrior filter on line 11 and sends it to the email +# address provided in the first command line argument, using neomutt, which obviously must be +# configured. There is probably more that can be done to format it correctly. Obviously, the two +# perl modules above are required. + +# Check if the recipient email address is provided +if (@ARGV < 1) { + print "Usage: $0 recipient_email\n"; + exit 1; +} + +my $recipient_email = $ARGV[0]; + +# Execute Taskwarrior command +my $task_cmd = "task status:pending project:w export"; +# my $task_cmd = "task status:pending limit:page -idea -killlist project.not:h.buy export"; +my $task_output; +open(my $task_fh, "-|", $task_cmd) or die "Can't execute Taskwarrior command: $!"; +{ + local $/ = undef; + $task_output = <$task_fh>; +} +close($task_fh); + +# Process Taskwarrior output +my $tasks = decode_json($task_output); +my @sorted_tasks = sort { ($a->{scheduled} // "9999") cmp ($b->{scheduled} // "9999") } @$tasks; + +# Compose email content +my $email_content = "Subject: Task Report\n\n"; +for my $task (@sorted_tasks) { + $email_content .= sprintf "%s - %s%s%s%s\n", + $task->{description}, + $task->{project} // "-", + $task->{scheduled} ? " - Scheduled: " . DateTime::Format::ISO8601->parse_datetime($task->{scheduled})->strftime("%Y-%m-%d %H:%M") : "", + $task->{due} ? " - Due: " . DateTime::Format::ISO8601->parse_datetime($task->{due})->strftime("%Y-%m-%d %H:%M") : "", + $task->{priority} ? " - Priority: " . $task->{priority} : ""; +} + +# Send email using Neomutt +my $neomutt_cmd = "neomutt -s \"Task Report\" $recipient_email"; +my ($neomutt_in, $neomutt_out); +my $neomutt_pid = open2($neomutt_out, $neomutt_in, $neomutt_cmd) or die "Can't execute Neomutt command: $!"; +print $neomutt_in $email_content; +close($neomutt_in); +waitpid($neomutt_pid, 0); + |