aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-11-18 16:11:39 +0000
committerMatthew Lemon <lemon@matthewlemon.com>2020-11-18 16:11:39 +0000
commitd5e13c5a1e6ec2f4b5096a2012eac17ce935b068 (patch)
tree9124570e80c5defc43a975af1a2e0b331dc2c2c3
initial commit
-rw-r--r--ssh.pl33
-rw-r--r--tw_hooks/hook_test.pl31
-rw-r--r--tw_hooks/on-add_schedule_tg.pl68
3 files changed, 132 insertions, 0 deletions
diff --git a/ssh.pl b/ssh.pl
new file mode 100644
index 0000000..d22d74d
--- /dev/null
+++ b/ssh.pl
@@ -0,0 +1,33 @@
+use strict;
+use warnings;
+use Net::OpenSSH;
+use JSON;
+
+my $host = "192.168.122.184";
+my $user = "lemon";
+
+my $ssh = Net::OpenSSH->new($host, user => $user);
+$ssh->error and die "Couldn't establish SSH connection: " . $ssh->error;
+
+# $ssh->system("ls -al ~") or die "remote command failed: " . $ssh->error;
+
+my $remote_host = $ssh->capture("hostname");
+
+print "Working on $remote_host.\n";
+
+# my @required_file = $ssh->capture("cat ~/.bashrc") or die "Cannot get requested file";
+# for (@required_file) {
+# # print $_ if $_ =~ /^if*/;
+# # print $_;
+# # print $_ if !($_ =~ /^#/); # strips the comments
+# print $_ if ($_ =~ /^#/); # just the comments
+# }
+# print("\n");
+
+# append to bollocks
+# my $append_text = "Tits\n";
+# $ssh->system({stdin_data => $append_text}, "cat >> bollocks.txt") or die "Cannot append text: " . $ssh->error;
+my %test_hash = ('first_name' => 'Matthew', 'surname' => 'Lemon');
+my $json_text = encode_json \%test_hash;
+print "$json_text\n";
+
diff --git a/tw_hooks/hook_test.pl b/tw_hooks/hook_test.pl
new file mode 100644
index 0000000..d3db593
--- /dev/null
+++ b/tw_hooks/hook_test.pl
@@ -0,0 +1,31 @@
+use strict;
+use warnings;
+use JSON;
+use Data::Dumper;
+
+# a test hook in Perl for taskwarrior
+
+# this must be JSON - this gets passed in my taskwarrior
+my $added_task = <STDIN>;
+
+my $hashref = decode_json $added_task;
+
+my $original_description = $hashref->{description};
+
+my $tags = $hashref->{tags};
+print $tags->[1];
+print "\n";
+
+print Dumper($hashref);
+
+$hashref->{description} =~ s/LEMON/BOLLOCKS/g;
+
+my $output = encode_json $hashref;
+
+# print $hashref->{"status"};
+# print "\n";
+# print $hashref->{scheduled};
+
+print $output;
+
+exit 0;
diff --git a/tw_hooks/on-add_schedule_tg.pl b/tw_hooks/on-add_schedule_tg.pl
new file mode 100644
index 0000000..a0690f5
--- /dev/null
+++ b/tw_hooks/on-add_schedule_tg.pl
@@ -0,0 +1,68 @@
+#!/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
+
+# 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 "Day is: ".$scheduled_dt->day . "\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;