diff options
author | Matthew Lemon <y@yulqen.org> | 2023-10-04 17:11:56 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2023-10-04 17:11:56 +0100 |
commit | 8b3a1c7f81cf85f8b227b05f8905709f18933d91 (patch) | |
tree | e60cacd78ad56a06fff0a572af3fc1e33c8a4919 | |
parent | 4d80902528335a2557a2d23e6d4b4af5e22e595f (diff) |
dayplan now searches archive.tgz for on this day in history
-rwxr-xr-x | calendar/dayplan_revised.pl | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/calendar/dayplan_revised.pl b/calendar/dayplan_revised.pl index fccc5cc..2d90f0e 100755 --- a/calendar/dayplan_revised.pl +++ b/calendar/dayplan_revised.pl @@ -7,10 +7,12 @@ use DateTime; use JSON; use Archive::Tar; use IO::Zlib; +use feature qw(say); sub search_in_tgz { my ($archive_file, $search_string) = @_; my $tar = Archive::Tar->new; + my @out; $tar->read($archive_file); # Iterate through the files in the archive in memory foreach my $file ($tar->get_files) { @@ -25,13 +27,36 @@ sub search_in_tgz { my @lines = split(/\n/, $file_content); foreach my $line (@lines) { if ($line =~ /$search_string/) { - print "File name: " . $file->name . ": " . $line . "\n"; + # print "File name: " . $file->name . ": " . $line . "\n"; + push(@out, $line); } } } } + return @out; } +sub this_day { + my ($month, $day) = @_; + my @out; + my $archive_path = "/home/lemon/Documents/Notes/journal/archives/journal_archive_aug23.tgz"; + my $tar = Archive::Tar->new; + $tar->read($archive_path); + foreach my $file ($tar->get_files) { + if ($file->name =~ /\d\d\d\d-$month-$day.md/) { + my @lines = split(/\n/, $file->get_content); + foreach my $line (@lines) { + if ($line =~ /^- \d\d:\d\d/) { + my $stripped = $file->name =~ s/\.md//r; + push @out, $stripped . " " . $line . "\n"; + } + } + } + } + return @out; +} + + my $dayplans = '/home/lemon/Documents/Notes/journal/day_plans'; #my $dayplans = "/tmp/dayplans"; @@ -170,6 +195,21 @@ sub timeblock { "; } +sub historic_lines_block { + my ($month, $day) = @_; + my @historic_lines = this_day($month, $day); + # foreach my $line (@historic_lines) { + # say $line; + # } + unshift @historic_lines, "\n## On this day in history....\n"; + if (scalar @historic_lines == 0) { + push @historic_lines, "There are no historic logs for today...\n"; + return @historic_lines; + } else { + return @historic_lines; + } +} + sub generate_text { my ($quicknotes_ref, $qfiles_ref) = get_quicknotes_and_quickfiles(); return @@ -181,7 +221,8 @@ sub generate_text { qnoteblock($quicknotes_ref, $qfiles_ref), remindersblock($year, $month, $day), schoolblock($day), - timeblock; + timeblock, + historic_lines_block($month, $day); } |