From e2c3adf5c0a364e8a39c7ab265a3f067cb9b7520 Mon Sep 17 00:00:00 2001 From: W1CDN Date: Sat, 24 Jun 2023 11:17:53 -0500 Subject: [PATCH] Stub out index/status page. --- api_app.py | 19 ++++++++++++++++--- templates/index.html | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 templates/index.html diff --git a/api_app.py b/api_app.py index a1c2dc2..fa3284f 100644 --- a/api_app.py +++ b/api_app.py @@ -1,4 +1,4 @@ -from flask import Flask, request +from flask import Flask, request, render_template from flask_restful import Resource, Api, reqparse from datetime import date, timedelta import configparser @@ -6,6 +6,7 @@ import csv import ast import glob import json, operator +import requests import sqlite3 api_app = Flask(__name__) api = Api(api_app) @@ -89,6 +90,18 @@ def select_frames(conn, n, from_, url_params): rows = cur.fetchall() return rows +@api_app.route('/') +def index(): + + # Get list of recent packets using API + # TODO use relative path + response = json.loads(requests.get("https://digi.w1cdn.net/aprs_api/packets").text)['data'] + return render_template('index.html', + station_call = config['Settings']['station_call'], + station_lat = config['Settings']['station_lat'], + station_lon = config['Settings']['station_lon'], + d = response) + class Packets(Resource): def get(self): # Handle arguments that may or may not exist @@ -103,7 +116,7 @@ class Packets(Resource): data = select_frames(conn, n = n, from_ = from_, url_params = request.args.to_dict()) # Sort by created date, descending (https://stackoverflow.com/a/45266808) #data.sort(key=operator.itemgetter('created'), reverse=True) - return {'data': data}, 200 # return data and 200 OK code + return {data}, 200 # return data and 200 OK code # Read config config = read_config() @@ -113,7 +126,7 @@ log_folder = config['Settings']['log_folder'] import subprocess subprocess.Popen(["python3","kiss_and_db.py"]) -api.add_resource(Packets, '/packets') # and '/locations' is our entry point for Locations +api.add_resource(Packets, '/packets') if __name__ == '__main__': api_app.run(debug=True, host='0.0.0.0', port=5001) # run our Flask app diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..a0eb753 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,39 @@ + + + + + {{station_call}} Status + + + + +

{{station_call}} Status

+

{{station_lat}}, {{station_lon}}

+ +

Recent RF Packets

+ + + + + + + + {% for i in d %} + + + + + + {% endfor %} +
from object_name created (utc) more
{{ i['from'] }} {{ i['object_name'] }} {{ i['created'] }} more +
+ +

Recent Stations

+Coming soon, see https://amiok.net/gitea/W1CDN/aprs_tool/issues/16. + + +