2023-04-05 16:28:39 -05:00
|
|
|
from flask import Flask
|
|
|
|
from flask_restful import Resource, Api, reqparse
|
|
|
|
import pandas as pd
|
|
|
|
import ast
|
2023-04-05 17:36:16 -05:00
|
|
|
import kiss
|
2023-04-05 16:28:39 -05:00
|
|
|
app = Flask(__name__)
|
2023-04-05 16:58:35 -05:00
|
|
|
api = Api(app)
|
|
|
|
|
2023-04-05 17:36:16 -05:00
|
|
|
### 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
|
|
|
|
|
2023-04-05 16:58:35 -05:00
|
|
|
class Users(Resource):
|
|
|
|
def get(self):
|
|
|
|
data = pd.read_csv('users.csv') # read CSV
|
|
|
|
data = data.to_dict() # convert dataframe to dictionary
|
|
|
|
return {'data': data}, 200 # return data and 200 OK code
|
2023-04-05 17:36:16 -05:00
|
|
|
|
2023-04-05 16:58:35 -05:00
|
|
|
class Locations(Resource):
|
|
|
|
def get(self):
|
|
|
|
data = pd.read_csv('locations.csv') # read CSV
|
|
|
|
data = data.to_dict() # convert dataframe to dictionary
|
|
|
|
return {'data': data}, 200 # return data and 200 OK code
|
2023-04-05 17:36:16 -05:00
|
|
|
|
2023-04-05 16:58:35 -05:00
|
|
|
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
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2023-04-05 17:36:16 -05:00
|
|
|
app.run(debug=True) # run our Flask app
|