From 215b5cf27529bb418f90fa6902fba1aa6343fad7 Mon Sep 17 00:00:00 2001 From: MathiasDPX Date: Mon, 30 Dec 2024 18:06:09 +0100 Subject: [PATCH] Handle null browser/os --- monitoring.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/monitoring.py b/monitoring.py index ca4f75c..6b6a736 100644 --- a/monitoring.py +++ b/monitoring.py @@ -153,7 +153,13 @@ if isInit: def log(ip:str, useragent:str, day:int) -> bool: if not isInit: return True - os = parse_os(useragent).family - browser = parse_user_agent(useragent).family - success = db.execute_query(f"INSERT INTO cinema_queries (ip, time, browser, os, day) VALUES (\'{ip}\', current_timestamp, \'{browser}\', \'{os}\', {day});") + os = parse_os(useragent) + browser = parse_user_agent(useragent) + + os_family = os.family if os != None else "unknown" + browser_family = browser.family if browser != None else "unknown" + + print(os_family, browser_family) + + success = db.execute_query(f"INSERT INTO cinema_queries (ip, time, browser, os, day) VALUES (\'{ip}\', current_timestamp, \'{browser_family}\', \'{os_family}\', {day});") return success \ No newline at end of file