From bae08a3a92130de84677b4663fa1c79511db985e Mon Sep 17 00:00:00 2001 From: Danilo Reyes Date: Mon, 2 Dec 2024 21:31:38 -0600 Subject: [PATCH] trakcer now calculates offline hours --- tuhmayto/tracker.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tuhmayto/tracker.py b/tuhmayto/tracker.py index c68d649..0792673 100644 --- a/tuhmayto/tracker.py +++ b/tuhmayto/tracker.py @@ -33,12 +33,15 @@ def log_activity(timestamp: str) -> None: def parse_last_seen(text: str) -> datetime | None: now = datetime.now() if "Visto por Ășltima vez" in text: + hours_match = re.search(r"(\d+) horas", text) minutes_match = re.search(r"(\d+) minutos", text) - if not minutes_match: - return None - minutes_ago = int(minutes_match.group(1)) - return now - timedelta(minutes=minutes_ago) - if "online" in text.lower(): + if hours_match: + hours_ago = int(hours_match.group(1)) + return now - timedelta(hours=hours_ago) + if minutes_match: + minutes_ago = int(minutes_match.group(1)) + return now - timedelta(minutes=minutes_ago) + elif "online" in text.lower(): return now return None