diff --git a/kiss_and_db.py b/kiss_and_db.py index 3cd25b1..d8e5320 100644 --- a/kiss_and_db.py +++ b/kiss_and_db.py @@ -61,6 +61,7 @@ def main(): 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+")" + try: # Insert data conn.execute(sql, list(a.values())) @@ -71,13 +72,17 @@ def main(): # It's not immediately needed, so I'm skipping it. # Build query # "from" is wrappedin [] because it is a reserved word and using '' doesn't work. - station_update = ", ".join((a['from'], a['created_unix'], "1")) - query3 = "INSERT INTO stations ([from], last_heard_unix, count) \ - VALUES("+station_update+", 1) \ - ON CONFLICT([from]) \ - DO UPDATE SET count = count + 1;" - # Insert/update data - conn.execute(query3) + 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) + except: + print("Stations table couldn't be updated.") conn.commit()