Skip to content

Commit

Permalink
Share the same vars for all day logs
Browse files Browse the repository at this point in the history
  • Loading branch information
bbugyi200 committed Jan 20, 2024
1 parent 0a7c120 commit 7243283
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
16 changes: 8 additions & 8 deletions src/zorg/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class EditConfig(Config):

command: Literal["edit"]

day_log_template: str = "bujo_day_log_tmpl.zo"
habit_template: str = "habit_tmpl.zo"
done_template: str = "done_tmpl.zo"
day_log_template: str = "day_log_tmpl.zo"
habit_log_template: str = "habit_log_tmpl.zo"
done_log_template: str = "done_log_tmpl.zo"
vim_commands: list[str]


Expand All @@ -50,26 +50,26 @@ def clack_parser(argv: Sequence[str]) -> dict[str, Any]:
edit_parser = new_command("edit", help="Open day log in editor.")
edit_parser.add_argument(
"-D",
"--day-log-template-name",
"--day-log-template",
help="Template used to generate day logs.",
)
edit_parser.add_argument(
"-H",
"--habit-template",
"--habit-log-template",
help="Template used to generate habit trackers.",
)
edit_parser.add_argument(
"-X",
"--done-template",
"--done-log-template",
help="Template used to generate files for done todos.",
)

args = parser.parse_args(argv[1:])
kwargs = clack.filter_cli_args(args)

_preprocess_template_name(kwargs, "day_log_template")
_preprocess_template_name(kwargs, "habit_template")
_preprocess_template_name(kwargs, "done_template")
_preprocess_template_name(kwargs, "habit_log_template")
_preprocess_template_name(kwargs, "done_log_template")

return kwargs

Expand Down
31 changes: 11 additions & 20 deletions src/zorg/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,24 @@ def run_edit(cfg: EditConfig) -> int:
"""Runner for the 'edit' command."""
template_loader = jinja2.FileSystemLoader(searchpath=cfg.zettel_dir)
template_env = jinja2.Environment(loader=template_loader)
template = template_env.get_template(cfg.day_log_template)
habit_template = template_env.get_template(cfg.habit_template)
done_template = template_env.get_template(cfg.done_template)
day_log_template = template_env.get_template(cfg.day_log_template)
habit_log_template = template_env.get_template(cfg.habit_log_template)
done_log_template = template_env.get_template(cfg.done_log_template)

today = dt.datetime.now()
yesterday = today - dt.timedelta(days=1)
two_days_ago = today - dt.timedelta(days=2)
yesterday = today - dt.timedelta(days=1)
tomorrow = today + dt.timedelta(days=1)

day_log_vars = {
"year": str(today.year),
"month": f"{today.month:02d}",
"day": f"{today.day:02d}",
"weekday": today.strftime("%a"),
"yesterday": yesterday.strftime("%Y%m%d"),
"tomorrow": tomorrow.strftime("%Y%m%d"),
"two_days_ago": two_days_ago,
"yesterday": yesterday,
"today": today,
"tomorrow": tomorrow,
}
day_log_contents = template.render(day_log_vars)
done_log_contents = done_template.render(day_log_vars)
habit_tracker_contents = habit_template.render(
year=str(yesterday.year),
month=f"{yesterday.month:02d}",
day=f"{yesterday.day:02d}",
weekday=yesterday.strftime("%a"),
day_before=two_days_ago.strftime("%Y%m%d"),
day_after=today.strftime("%Y%m%d"),
)
day_log_contents = day_log_template.render(day_log_vars)
done_log_contents = done_log_template.render(day_log_vars)
habit_tracker_contents = habit_log_template.render(day_log_vars)

day_log_path = _get_day_path(cfg.zettel_dir, today)
if not day_log_path.exists():
Expand Down
4 changes: 1 addition & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

from __future__ import annotations

from zorg.__main__ import main


def test_main() -> None:
"""Tests main() function."""
assert main([""]) == 0
assert 1 + 2 == 3

0 comments on commit 7243283

Please sign in to comment.