From 9c11d8d4949e4fe51f94fd403f4b43d20a2baa68 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 12 Jul 2023 09:57:54 -0500 Subject: [PATCH] Try something else --- kiss_and_db.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/kiss_and_db.py b/kiss_and_db.py index e9b9723..3b63a78 100644 --- a/kiss_and_db.py +++ b/kiss_and_db.py @@ -61,11 +61,11 @@ def main(): # Build an INSERT statement based on the fields we have from the frame attrib_names = ', '.join('"%s"' % w for w in a.keys()) attrib_values = ", ".join("?" * len(a.keys())) - sql = "INSERT INTO frames ("+attrib_names+") VALUES ("+attrib_values+")" - conn.commit() + try: # Insert data + sql = "INSERT INTO frames ("+attrib_names+") VALUES ("+attrib_values+")" conn.execute(sql, list(a.values())) # TODO update stations table here @@ -75,18 +75,19 @@ def main(): # Build query # "from" is wrappedin [] because it is a reserved word and using '' doesn't work. # https://www.sqlite.org/lang_keywords.html - try: - station_update = "'"+a['from'] +"', '"+ str(a['created_unix']) +"', '1'" - query3 = "INSERT INTO stations ([from], last_heard_unix, count) \ - VALUES("+station_update+") \ - ON CONFLICT([from]) \ - DO UPDATE SET count = count + 1;" - print(query3) - # Insert/update data - conn.execute(query3) - conn.commit() - except: - print("Stations table couldn't be updated.") + #try: + station_update = "'"+a['from'] +"', '"+ str(a['created_unix']) +"', '1'" + query3 = "INSERT INTO stations ([from], last_heard_unix, count) \ + VALUES("+station_update+") \ + ON CONFLICT([from]) \ + DO UPDATE SET count = count + 1;" + print(query3) + # Insert/update data + conn.execute(query3) + + conn.commit() + #except: + # print("Stations table couldn't be updated.") # TODO remove packets that are older ('created') than a limit set in config.ini # "5 minutes" also works