From cc89ab1a4ccd4d363f9c7d47d54f10b29a818193 Mon Sep 17 00:00:00 2001
From: W1CDN <matthew.burtonkelly@gmail.com>
Date: Thu, 27 Apr 2023 19:19:12 -0500
Subject: [PATCH] Don't mess with frame if it can't be parsed.

---
 kiss_and_db.py | 55 +++++++++++++++++++++++++-------------------------
 1 file changed, 28 insertions(+), 27 deletions(-)

diff --git a/kiss_and_db.py b/kiss_and_db.py
index a38dfd3..e94c058 100644
--- a/kiss_and_db.py
+++ b/kiss_and_db.py
@@ -90,35 +90,36 @@ def main():
         for frame in ki.read(min_frames=1):
             try:
                 a = aprslib.parse(str(frame))
-            except:
-                a = dict()
-            a['station_call'] = config['Settings']['station_call']
-            a['station_lat'] = config['Settings']['station_lat']
-            a['station_lon'] = config['Settings']['station_lon']
-            print(a)
-            # Make this a string and deal with it later (probably a mistake)
-            a['path'] = str(a['path'])
-            # Store true/false as 1/0
-            if 'alive' in a:
-                if a['alive'] == True:
-                    a['alive'] = 1
-                else:
-                    a['alive'] = 0
-            # 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+")"
-            try:
-                # Insert data
-                conn.execute(sql, list(a.values()))
-                conn.commit()
+                a['station_call'] = config['Settings']['station_call']
+                a['station_lat'] = config['Settings']['station_lat']
+                a['station_lon'] = config['Settings']['station_lon']
+                print(a)
+                # Make this a string and deal with it later (probably a mistake)
+                a['path'] = str(a['path'])
+                # Store true/false as 1/0
+                if 'alive' in a:
+                    if a['alive'] == True:
+                        a['alive'] = 1
+                    else:
+                        a['alive'] = 0
+                # 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+")"
+                try:
+                    # Insert data
+                    conn.execute(sql, list(a.values()))
+                    conn.commit()
 
-                # TODO remove packets that are older ('created') than a limit set in config.ini
-                # "5 minutes" also works
-                conn.execute("DELETE FROM frames WHERE created < DATETIME('now', '"+config['Settings']['keep_time']+"')")
-                conn.commit()
+                    # TODO remove packets that are older ('created') than a limit set in config.ini
+                    # "5 minutes" also works
+                    conn.execute("DELETE FROM frames WHERE created < DATETIME('now', '"+config['Settings']['keep_time']+"')")
+                    conn.commit()
+                except:
+                    print("Error with SQLite!")
             except:
-                print("Error with SQLite!")
+                print("Frame could not be parsed.")
+
 
         conn.close()