From 5ce44228ccf02c3550e764e5db749659a2b38ae2 Mon Sep 17 00:00:00 2001 From: mbridak Date: Wed, 30 Oct 2024 13:35:45 -0700 Subject: [PATCH] @mbridak add_callhistory_item --- not1mm/lib/database.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/not1mm/lib/database.py b/not1mm/lib/database.py index e22b9f6..fd8fba3 100644 --- a/not1mm/lib/database.py +++ b/not1mm/lib/database.py @@ -387,6 +387,28 @@ def fetch_contest_by_id(self, contest_nr: str) -> dict: logger.debug("%s", exception) return {} + def add_callhistory_item(self, history: dict) -> None: + """Add an item to the call history db""" + pre = "INSERT INTO CALLHISTORY(" + values = [] + columns = "" + placeholders = "" + for key in history.keys(): + columns += f"{key}," + values.append(history[key]) + placeholders += "?," + post = f") VALUES({placeholders[:-1]});" + sql = f"{pre}{columns[:-1]}{post}" + + try: + with sqlite3.connect(self.database) as conn: + logger.info("%s", sql) + cur = conn.cursor() + cur.execute(sql, tuple(values)) + conn.commit() + except sqlite3.Error as exception: + logger.info("%s", exception) + def add_contest(self, contest: dict) -> None: """Add Contest"""