From a7efb12d5cc1a92204971be6e52d19ffd214dcad Mon Sep 17 00:00:00 2001 From: Christian Mueller Date: Thu, 23 Apr 2026 22:51:56 +0200 Subject: [PATCH] fix: robust AIDA CSV parsing (handle ~~ vs ~ prefix, comma separator) CSV format is '~~00341~~,~~0~~' or '~00341~~,~~0~~'. Strip tildes and compare bare numbers instead of relying on startswith/endswith which breaks with inconsistent tilde counts. Co-Authored-By: Claude Opus 4.6 (1M context) --- scheduler.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/scheduler.py b/scheduler.py index 23b183c..f8277a1 100644 --- a/scheduler.py +++ b/scheduler.py @@ -24,21 +24,40 @@ def read_aida_csv(csv_path): return [] +def _extract_nr(value): + """Extract bare number from ~~00341~~ -> 00341.""" + return value.strip().strip("~") + + def determine_aida_status(lines, personal_nr, settings): """Determine AIDA status for a user based on their personal number.""" if not personal_nr or not lines: return None - matching = [l for l in lines if l.startswith(personal_nr.lower())] + nr = _extract_nr(personal_nr) + if not nr: + return None + + # Find line containing this personal number + matching = [l for l in lines if nr in l] if not matching: return None line = matching[0] - if line.endswith(settings.get("aida_status_abwesend", "~~0~~")): + # Check status part (after comma or at end) + status_abwesend = _extract_nr(settings.get("aida_status_abwesend", "~~0~~")) + status_anwesend = _extract_nr(settings.get("aida_status_anwesend", "~~1~~")) + status_homeoffice = _extract_nr(settings.get("aida_status_homeoffice", "~~2~~")) + + # Get the status value (last part after comma, stripped of ~) + parts = line.split(",") + status_val = _extract_nr(parts[-1]) if len(parts) > 1 else "" + + if status_val == status_abwesend: return "abwesend" - if line.endswith(settings.get("aida_status_anwesend", "~~1~~")): + if status_val == status_anwesend: return "anwesend" - if line.endswith(settings.get("aida_status_homeoffice", "~~2~~")): + if status_val == status_homeoffice: return "homeoffice" return None