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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										39
									
								
								templates/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								templates/index.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
<html lang="en">
 | 
			
		||||
<head>
 | 
			
		||||
    <meta charset="UTF-8">
 | 
			
		||||
    <title>{{station_call}} Status</title>
 | 
			
		||||
 | 
			
		||||
    <style>
 | 
			
		||||
      table, th, td {
 | 
			
		||||
        border: 1px solid black;
 | 
			
		||||
      }
 | 
			
		||||
    </style>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
   <h1>{{station_call}} Status</h1>
 | 
			
		||||
   <h2>{{station_lat}}, {{station_lon}}</h2>
 | 
			
		||||
 | 
			
		||||
<h3> Recent RF Packets </h3>
 | 
			
		||||
   <table>
 | 
			
		||||
     <tr>
 | 
			
		||||
      <th> from </th>
 | 
			
		||||
      <th> object_name </th>
 | 
			
		||||
      <th> created (utc) </th>
 | 
			
		||||
      <th> more </th>
 | 
			
		||||
    </tr>
 | 
			
		||||
        {% for i in d %}
 | 
			
		||||
     <tr>
 | 
			
		||||
       <td> <a href="https://digi.w1cdn.net/aprs_api/packets?from={{ i['from'] }}">{{ i['from'] }}</a> </td>
 | 
			
		||||
       <td> {{ i['object_name'] }} </td>
 | 
			
		||||
       <td> {{ i['created'] }} </td>
 | 
			
		||||
       <td> <a href="https://digi.w1cdn.net/aprs_api/packets?id={{ i['id'] }}">more</a>
 | 
			
		||||
     </tr>
 | 
			
		||||
      {% endfor %}
 | 
			
		||||
  </table>
 | 
			
		||||
 | 
			
		||||
<h3> Recent Stations </h3>
 | 
			
		||||
Coming soon, see <a href="https://amiok.net/gitea/W1CDN/aprs_tool/issues/16">https://amiok.net/gitea/W1CDN/aprs_tool/issues/16</a>.
 | 
			
		||||
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
		Reference in New Issue
	
	Block a user