aboutsummaryrefslogtreecommitdiffstats
path: root/tw/tw_hooks/first_attempt.pl
diff options
context:
space:
mode:
authorMatthew Lemon <matt@matthewlemon.com>2022-09-18 21:12:26 +0100
committerMatthew Lemon <matt@matthewlemon.com>2022-09-18 21:12:26 +0100
commitc67ec9f37c46f42297a6844806debe439be290cd (patch)
tree23089bf978eccb1da6cb4918bace71ad3f884230 /tw/tw_hooks/first_attempt.pl
parent49d443767d1290db4374ab0059382b047d902567 (diff)
tidy up files
Diffstat (limited to 'tw/tw_hooks/first_attempt.pl')
-rw-r--r--tw/tw_hooks/first_attempt.pl88
1 files changed, 88 insertions, 0 deletions
diff --git a/tw/tw_hooks/first_attempt.pl b/tw/tw_hooks/first_attempt.pl
new file mode 100644
index 0000000..5423180
--- /dev/null
+++ b/tw/tw_hooks/first_attempt.pl
@@ -0,0 +1,88 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use feature qw(say);
+use JSON;
+use DateTime;
+use DateTime::Format::ISO8601;
+
+# a test hook in Perl for taskwarrior
+
+
+# ALGORITHM
+
+# Parse the due attribute from TW
+# Convert it into Remind format
+# Log into remote server
+# Check for presece or remind file
+# If it is there, back it up
+# Append the Remind formatted line to the original remind file
+
+my @short_months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
+my @days_of_week = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday);
+
+# this must be JSON - this gets passed in my taskwarrior
+my $added_task = <STDIN>;
+
+my $hashref = decode_json $added_task;
+
+sub parse_scheduled
+{
+ my $sched_date = shift;
+ return DateTime::Format::ISO8601->parse_datetime($sched_date);
+}
+
+if ($hashref->{scheduled}) {
+ my $scheduled_dt = parse_scheduled $hashref->{scheduled};
+ print "Scheduled Date:\n";
+ print "---------------\n";
+ print "Year is: ".$scheduled_dt->year() . "\n";
+ print "Month is: ".$scheduled_dt->month() . "\n";
+ print "Month again is: ".$short_months[$scheduled_dt->month()-1] . "\n";
+ print "Day is: ".$scheduled_dt->day() . "\n";
+ # O
+ # # wday() is builtin?
+ # https://stackoverflow.com/questions/10919585/extract-day-of-week-using-perl-and-mysql-date-format
+ # https://metacpan.org/pod/Time::Piece
+ print "Day of week is: ".$days_of_week[$scheduled_dt->day_of_week() % 7] . "\n";
+ print "Quarter is: ".$scheduled_dt->quarter(). "\n";
+ print "\n";
+}
+
+# if ($hashref->{scheduled}) {
+# my $sched_date = $hashref->{scheduled};
+# my $year = substr $sched_date, 0, 4;
+# my $month = substr $sched_date, 4, 2;
+# my $day = substr $sched_date, 6, 2;
+
+# my $dt = DateTime->new(
+# year => $year,
+# month => $month,
+# day => $day,
+# time_zone => 'Europe/London',
+# );
+
+# print "Year is: $dt->year" . "\n";
+# print "Month is: $dt->month" . "\n";
+# print "Day is: $dt->$day" . "\n";
+# print "\n";
+# }
+
+my $original_description = ${$hashref}{description};
+# my $original_description = $hashref->{description}; # alternative (and
+# preferred)
+
+my $tags = ${$hashref}{tags}; # alternative - not using -> in the ref
+
+$hashref->{description} = "DfT Task: " . $original_description if scalar grep {$_ eq "dft" } @{$tags};
+# same as
+# $hashref->{description} = "DfT Task: " . $original_description if scalar grep {$_ eq "dft" } @$tags;
+# You don't need the {} brackets! see perlreftut - The Rest section near the
+# end.
+
+my $output = encode_json $hashref;
+
+print $output;
+
+exit 0;