From d2479746ebc03cf45009156ef9c3d704b46a6db8 Mon Sep 17 00:00:00 2001
From: mattbk <mattbk@users.noreply.github.com>
Date: Wed, 5 Apr 2023 18:21:37 -0500
Subject: [PATCH] Start work reading from direwolf log files.

---
 app.py | 46 ++++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 22 deletions(-)

diff --git a/app.py b/app.py
index ae9c623..106f002 100644
--- a/app.py
+++ b/app.py
@@ -3,31 +3,10 @@ from flask_restful import Resource, Api, reqparse
 import pandas as pd
 import ast
 import kiss
+import glob
 app = Flask(__name__)
 api = Api(app)
 
-### This block from https://groups.io/g/direwolf/message/3543
-import socket
-
-s = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
-s.connect(("192.168.0.30", 8000));
-
-# R frame for version information
-R_frame = b'\0\0\0\0R\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0';
-s.sendall(R_frame);
-msg = s.recv(1024);
-### End block
-
-### This block from https://github.com/ampledata/kiss/blob/master/examples/socket_read.py
-def print_frame(frame):
-    print(aprs.Frame(frame[1:]))
-def p(x): print(x)  # prints whatever is passed in.
-ki = kiss.TCPKISS(host='192.168.0.30', port=8001)
-ki.start()
-#ki.read(callback=print_frame)
-ki.read(callback=p)
-### End block
-
 class Users(Resource):
     def get(self):
         data = pd.read_csv('users.csv')  # read CSV
@@ -40,8 +19,31 @@ class Locations(Resource):
         data = data.to_dict()  # convert dataframe to dictionary
         return {'data': data}, 200  # return data and 200 OK code
 
+# Read some log files
+list_stacked = pd.DataFrame()
+file_list = glob.glob("logs/*.log")
+print(file_list)
+for file in file_list:
+    file1 = pd.read_csv(file)
+    list_stacked = pd.concat([list_stacked, file1])
+
+# TODO get rid of NaN in JSON data? Either blank them or wrap in quotes.
+# https://jsoneditoronline.org
+# SyntaxError: JSON.parse: unexpected character at line 8818 column 20 of the JSON data
+#             "104": NaN,
+
+# TODO do I need to rearrange the data to a different format? I want all the
+# data for one packet (one row) together.
+
+class Packets(Resource):
+    def get(self):
+        data = list_stacked
+        data = data.to_dict()  # convert dataframe to dictionary
+        return {'data': data}, 200  # return data and 200 OK code
+
 api.add_resource(Users, '/users')  # '/users' is our entry point for Users
 api.add_resource(Locations, '/locations')  # and '/locations' is our entry point for Locations
+api.add_resource(Packets, '/packets')  # and '/locations' is our entry point for Locations
 
 if __name__ == '__main__':
     app.run(debug=True)  # run our Flask app