From 2ab53d7a9329880abb27a07cdfce24f60a78ea90 Mon Sep 17 00:00:00 2001 From: fz0x1 Date: Tue, 8 Apr 2025 14:51:03 +0200 Subject: [PATCH] 20250408.1744116663 --- global/scripts/bin/diary.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/global/scripts/bin/diary.py b/global/scripts/bin/diary.py index b6c4ae9..716c991 100755 --- a/global/scripts/bin/diary.py +++ b/global/scripts/bin/diary.py @@ -20,11 +20,13 @@ import time import urllib.parse import urllib.request from concurrent.futures import ThreadPoolExecutor, as_completed -from datetime import datetime, timedelta, timezone +from datetime import datetime, timezone from pathlib import Path +from zoneinfo import ZoneInfo DB_NAME = Path("metadata.db") -TZ = 1 +# TZ = 1 +TZ = ZoneInfo("Europe/Warsaw") TOOLS = ("jrnl", "sqlite3") FILES = (".jpeg", ".jpg", ".png", ".gif") FILES_PATH = Path("attachments") @@ -87,7 +89,9 @@ def get_diary_path_by_name(name: str): def make_tz_unixtime(target_time: str): return int( ( - datetime.strptime(target_time, "%Y-%m-%dT%H:%M:%SZ") + timedelta(hours=TZ) + datetime.strptime(target_time, "%Y-%m-%dT%H:%M:%SZ") + .replace(tzinfo=ZoneInfo("UTC")) + .astimezone(TZ) ).timestamp() ) @@ -102,8 +106,11 @@ def find_closest_entry(data, target_timestamp: int): def convert_diary_date(date_str): try: - dt = datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%SZ") + timedelta(hours=TZ) - return dt.strftime("%d %b %Y at %H:%M:%S:") + return ( + datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%SZ") + .replace(tzinfo=ZoneInfo("UTC")) + .astimezone(TZ) + ).strftime("%d %b %Y at %H:%M:%S:") except ValueError: return None @@ -408,7 +415,7 @@ def doctor(): if check_diary: def check_jrnl(metadata: list): - dt = datetime.fromtimestamp(metadata[1], tz=timezone(timedelta(hours=TZ))) + dt = datetime.fromtimestamp(metadata[1], tz=TZ) diary_datetime = dt.strftime("%Y/%m/%d at %I:%M:%S %p") try: result = subprocess.run(