aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <matt@matthewlemon.com>2022-09-22 13:50:07 +0100
committerMatthew Lemon <matt@matthewlemon.com>2022-09-22 13:50:07 +0100
commit25ba83f0b9af172b355a5b8d3d584ffeaa49a432 (patch)
tree814fd861e360c501a5ae1a3502b036d02672dce2
parent8cede18963c4fcb6728ca07249d2fe709be065b1 (diff)
finish basic refactor
-rwxr-xr-xcalendar/dayplan_revised.pl105
1 files changed, 77 insertions, 28 deletions
diff --git a/calendar/dayplan_revised.pl b/calendar/dayplan_revised.pl
index a5f8604..4dc4ce6 100755
--- a/calendar/dayplan_revised.pl
+++ b/calendar/dayplan_revised.pl
@@ -5,7 +5,8 @@ use strict;
use warnings;
use DateTime;
-my $dayplans = '/home/lemon/Notes/journal/day_plans';
+# my $dayplans = '/home/lemon/Notes/journal/day_plans';
+my $dayplans = "/tmp";
sub parse_args {
my $numargs = $#ARGV + 1;
@@ -52,21 +53,18 @@ sub get_quicknotes_and_quickfiles {
return (\@quicknotes, \@qfiles);
}
-
-sub schoolblock {
- my $day = shift;
- if ($day =~ /Saturday|Sunday/) {
- return "";
- } else
- {
- return "
-08:15 - 08:20 - Harvey to school
-08:45 - 09:00 - Sophie to school
-09:15 - 09:30 - Email";
- }
+sub headerblock {
+ my $dt = shift;
+ my $d = shift;
+ my $y = shift;
+ my $weekday = shift;
+ my $mname = $dt->month_name;
+ return "Goal for $weekday $d $mname $y: [replace this with your goal]
+---\n
+";
}
-sub quoteblock {
+sub qnoteblock {
$" = "";
my $quicknotes_ref =shift;
my $qfiles_ref = shift;
@@ -79,27 +77,78 @@ sub quoteblock {
$qnote_block = "@{$quicknotes_ref}"."from:"."\n"."@{$qfiles_ref}";
}
return $qnote_block;
- }
+}
-sub headerblock {
- my $dt = shift;
- my $d = shift;
- my $y = shift;
- my $weekday = shift;
- my $mname = $dt->month_name;
- return "Goal for $weekday $d $mname $y: [replace this with your goal]
----
-";
+sub schoolblock {
+ my $day = shift;
+ if ($day =~ /Saturday|Sunday/) {
+ return "";
+ } else
+ {
+ return "
+08:15 - 08:20 - Harvey to school
+08:45 - 09:00 - Sophie to school
+09:15 - 09:30 - Email";
+ }
}
-sub get_reminders_from_server {
+sub remindersblock {
my ($y, $m, $d) = @_;
my $reminders = qx(ssh bobbins remind ~/.reminders $y-$m-$d);
$reminders =~ s/\s{2,}/\n/gs;
$reminders =~ s/^Reminders.+\:\n//;
- return $reminders;
+ my $rheader = "\nReminders:\n----------\n";
+ return $rheader . $reminders;
+}
+
+sub timeblock {
+ return "
+09:30 - 10:00 -
+10:00 - 11:00 -
+11:00 - 12:00 -
+12:15 - 13:00 - Lunch
+13:00 - 14:00 -
+14:00 - 15:00 -
+15:00 - 16:00 -
+16:00 - 17:00 -
+";
+}
+
+sub generate_text {
+ my ($quicknotes_ref, $qfiles_ref) = get_quicknotes_and_quickfiles();
+ return
+ headerblock($date, $day, $year, $weekday),
+ qnoteblock($quicknotes_ref, $qfiles_ref),
+ remindersblock($year, $month, $day),
+ schoolblock($day),
+ timeblock;
+}
+
+
+sub write_file {
+ my $f = shift;
+ my $dt = shift;
+
+ open( FH, ">$f");
+ print FH generate_text;
+ my $today = DateTime->today;
+ if ($today != $dt) {
+ printf (FH "\nWARNING: This dayplan was generated in advance on %d-%02d-%d. Reminders and quicknotes may not be up to date.", $today->year, $today->month, $today->day);
+ }
+
+ close FH;
+ exec("vim", "$f");
}
+sub main {
+ my $today_planner = sprintf("%s/%d-%02d-%02d.txt", $dayplans, $year ,$month, $day);
+
+ if (-e $today_planner) {
+ exec("vim", "$today_planner");
+ } else
+ {
+ write_file($today_planner, $date);
+ }
+}
-my ($quicknotes_ref, $qfiles_ref) = get_quicknotes_and_quickfiles();
-print headerblock($date, $day, $year, $weekday);
+main();