aboutsummaryrefslogtreecommitdiffstats
path: root/clear_and_post_quicknote.pl
blob: 52b56a52b101abd1b6c69877e427ecb646beefbe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env -S perl -w

use 5.010;
use warnings;
use strict;
use DateTime;
use File::Copy;
use Cwd qw(getcwd);

my $description = $ARGV[0];

if (not defined $description) {
    print "Please pass even a paltry introductory sentence in quotes. Thanks.\n";
    exit;
}

sub get_quicknotes {
    my $quicknote_file = "/home/lemon/Documents/Notes/quicknote.md";
    my $bak = "/home/lemon/Documents/Notes/quicknote.md-BAK";
    copy($quicknote_file, $bak) or die "Failed to make backup of file: $!";
    my @quicknotes;
    open my $fh, "<", $quicknote_file or die "Cannot open quicknote.md file";
    while (<$fh>) {
        if ($_ =~ /^- (.*)$/ || $_ =~ /(\[.*)$/) {
            push @quicknotes => "- $1\n";
        }
    }
    truncate $quicknote_file, 0;
    return \@quicknotes;
}


my $now = DateTime->now;
my $day_name = $now->day_name;
my $day = $now->day;
my $month = $now->month_name;
my $year = $now->year;

my $outfile = "/home/lemon/code/html/yulqen.org/content/techjournal/quicknote_capture_${day}_${month}_$year.md";

my $frontmatter = <<TEXT;
---
title: "Quicknote capture $day_name $day $month $year"
date: $now
draft: false
categories: ["Tech"]
tags: ['quicknotes']
---

$description

TEXT

my $qn_ref = get_quicknotes();
open my $FH, ">>", $outfile or die $!;
print $FH $frontmatter;
foreach (@{$qn_ref}) {
    print $FH $_;
}
close($FH);

chdir "/home/lemon/code/html/yulqen.org";
say getcwd();
# my @gitstatuscmd = ("git", "status");
my @gitaddcmd = ("git add -A");
my @gitcommitcmd = ("git commit -m 'update'");
my @gitpushcmd = ("git push");
my @pushcmd = ("make push");
# system(@gitaddcmd) or die "Cannot do git add $?";
# system(@gitcommitcmd) or die "Cannot do git commit: $?";
system(@pushcmd) or die "Cannot push the file to the remote: $?";
# system(@gitpushcmd) or die "Cannot do git push: $?";

say "Done!";