aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tw_hooks/scratch.pl21
1 files changed, 15 insertions, 6 deletions
diff --git a/tw_hooks/scratch.pl b/tw_hooks/scratch.pl
index 8aa5e5b..ec74df3 100644
--- a/tw_hooks/scratch.pl
+++ b/tw_hooks/scratch.pl
@@ -4,6 +4,7 @@ use feature qw(say);
use JSON;
use DateTime;
use DateTime::Format::ISO8601;
+use Net::OpenSSH;
my @short_months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
@@ -19,6 +20,7 @@ sub parse_scheduled
# Parse the scheduled attribute from TW
my $added_task = <STDIN>;
+my $work_rem_file = '~/.reminders/work.rem';
my $decoded_task = decode_json $added_task;
my $original_description = ${$decoded_task}{description};
my $tags = ${$decoded_task}{tags}; # alternative - not using -> in the ref
@@ -33,27 +35,34 @@ if ($decoded_task->{scheduled} and (scalar grep {$_ eq "dft" } @{$tags})) {
my $min = $scheduled_dt->minute();
my $time = $scheduled_dt->hms();
# Convert it into Remind format
- my $remind_line = "REM $date $month $year AT $time $original_description";
+ my $remind_line = "REM $date $month $year AT $time MSG $original_description \%b\n";
# Log into remote server
- my $host = "192.168.122.184";
+ my $host = $ENV{"TW_HOOK_REMIND_REMOTE_HOST"} or die "Cannot get TW_HOOK_REMIND_REMOTE_HOST environment variable";
my $user = "lemon";
my $ssh = Net::OpenSSH->new($host, user => $user);
$ssh->error and die "Couldn't establish SSH connection: " . $ssh->error;
+ # Check for presece or remind file
+ if ($ssh->test("ls $work_rem_file") != 1) { die "Cannot find $work_rem_file on $host."};
+
+ # If it is there, back it up
+ $ssh->system("mv $work_rem_file $work_rem_file.bak");
+
+ # Append the Remind formatted line to the original remind file
$ssh->system({stdin_data => $remind_line}, "cat >> ~/.reminders/work.rem") or die "Cannot append text: " . $ssh->error;
+
+ # Reset the back up
+ $ssh->system("mv $work_rem_file.bak $work_rem_file");
- print $decoded_task;
+ print encode_json $decoded_task;
} else {
print encode_json $decoded_task;
}
-# Check for presece or remind file
-# If it is there, back it up
-# Append the Remind formatted line to the original remind file