diff options
author | Mark Powers <mark@marks.kitchen> | 2021-09-12 15:50:50 -0500 |
---|---|---|
committer | Mark Powers <mark@marks.kitchen> | 2021-09-12 15:50:50 -0500 |
commit | f21906aa2eac62a336c8b8e49d0cdf9fb1d76748 (patch) | |
tree | 36850f1918acf7214c85413912a5dbbe3e4d04e4 /journal.py | |
parent | d78b6d188eb9ba206c8769b41c8021e7ba52ef98 (diff) |
Add journal command
Diffstat (limited to 'journal.py')
-rw-r--r-- | journal.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/journal.py b/journal.py new file mode 100644 index 0000000..484c78d --- /dev/null +++ b/journal.py @@ -0,0 +1,40 @@ +from datetime import datetime, timedelta + +from main import get_tree, get_single_page, create + +def args_for_date(date): + return { + "path": date.strftime("journal/%Y/%b/%d").lower(), + "title": date.strftime("%B %-d"), + } + + +def fill_in_pages(args): + last_date = None + for page in get_tree(["journal"]): + try: + date = datetime.strptime(page["path"], "journal/%Y/%b/%d") + if last_date is None or date > last_date: + last_date = date + except ValueError: + continue + today = datetime.now().date() + if last_date is None: + last_date = today + pending_date = last_date.date() + while pending_date < today: + pending_date += timedelta(days=1) + create(args_for_date(pending_date)) + + +def today(args): + """ + Creates a journal page with the path "journal/YYYY/MM/DD" + + args: used + """ + args = args_for_date(datetime.now().date()) + if get_single_page(args["path"]) is not None: + edit(args) + else: + create(args) |