Try something else

This commit is contained in:
Matt Old Account 2023-07-12 09:57:54 -05:00
parent e3cb68551b
commit 9c11d8d494

View File

@ -61,11 +61,11 @@ def main():
# Build an INSERT statement based on the fields we have from the frame # Build an INSERT statement based on the fields we have from the frame
attrib_names = ', '.join('"%s"' % w for w in a.keys()) attrib_names = ', '.join('"%s"' % w for w in a.keys())
attrib_values = ", ".join("?" * len(a.keys())) attrib_values = ", ".join("?" * len(a.keys()))
sql = "INSERT INTO frames ("+attrib_names+") VALUES ("+attrib_values+")"
conn.commit()
try: try:
# Insert data # Insert data
sql = "INSERT INTO frames ("+attrib_names+") VALUES ("+attrib_values+")"
conn.execute(sql, list(a.values())) conn.execute(sql, list(a.values()))
# TODO update stations table here # TODO update stations table here
@ -75,18 +75,19 @@ def main():
# Build query # Build query
# "from" is wrappedin [] because it is a reserved word and using '' doesn't work. # "from" is wrappedin [] because it is a reserved word and using '' doesn't work.
# https://www.sqlite.org/lang_keywords.html # https://www.sqlite.org/lang_keywords.html
try: #try:
station_update = "'"+a['from'] +"', '"+ str(a['created_unix']) +"', '1'" station_update = "'"+a['from'] +"', '"+ str(a['created_unix']) +"', '1'"
query3 = "INSERT INTO stations ([from], last_heard_unix, count) \ query3 = "INSERT INTO stations ([from], last_heard_unix, count) \
VALUES("+station_update+") \ VALUES("+station_update+") \
ON CONFLICT([from]) \ ON CONFLICT([from]) \
DO UPDATE SET count = count + 1;" DO UPDATE SET count = count + 1;"
print(query3) print(query3)
# Insert/update data # Insert/update data
conn.execute(query3) conn.execute(query3)
conn.commit()
except: conn.commit()
print("Stations table couldn't be updated.") #except:
# print("Stations table couldn't be updated.")
# TODO remove packets that are older ('created') than a limit set in config.ini # TODO remove packets that are older ('created') than a limit set in config.ini
# "5 minutes" also works # "5 minutes" also works