Stub out index/status page.
This commit is contained in:
19
api_app.py
19
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
|
||||
|
Reference in New Issue
Block a user