From df2469e1054fa229e3a9723118d37c78b1f42b84 Mon Sep 17 00:00:00 2001 From: fz0x1 Date: Fri, 17 Jan 2025 21:07:02 +0100 Subject: [PATCH] 20250117.1737144422 --- global/scripts/bin/diary.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/global/scripts/bin/diary.py b/global/scripts/bin/diary.py index 5a9720a..8c8f380 100755 --- a/global/scripts/bin/diary.py +++ b/global/scripts/bin/diary.py @@ -259,8 +259,17 @@ def fetch_weather( def doctor(): - if len(sys.argv) < 3: + args_len = len(sys.argv) + check_diary = False + fix_diary = False + if args_len < 3: sys.exit("Usage: script.py doctor ") + if args_len >= 4 and sys.argv[3] == "check_diary": + check_diary = True + + if args_len >= 4 and sys.argv[3] == "check_and_fix_diary": + fix_diary = True + check_diary = True diary_name = sys.argv[2] diary_path = get_diary_path_by_name(diary_name).parent @@ -283,6 +292,32 @@ def doctor(): if not location: print(f"There is no location info about {m[0]} - {m[1]}") + if check_diary: + dt = datetime.fromtimestamp(m[1], tz=timezone(timedelta(hours=TZ))) + diary_datetime = dt.strftime("%Y/%m/%d at %I:%M:%S %p") + # print(diary_datetime) + try: + result = subprocess.run( + ["jrnl", diary_name, "-on", diary_datetime], + check=True, + capture_output=True, + text=True, + ) + if not result.stdout: + print( + f"There is some metadata that is not associated with a diary entity: {diary_datetime}." + ) + if not fix_diary: + print( + "You can automatically remove it by running the scripts with 'check_and_fix_diary' argument." + ) + else: + remove_metadata(conn, m[0]) + print("The problem was fixed.") + except subprocess.CalledProcessError as e: + print(e) + raise + def make_hash(file: Path): sha256_hash = hashlib.sha256()