aboutsummaryrefslogtreecommitdiff
path: root/journal.py
blob: 484c78d0ff23f3f4f8ea340737f19f1d9a59a198 (plain)
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
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)