Use stations table on index.html.

This commit is contained in:
W1CDN 2023-07-09 11:22:23 -05:00
parent c0ff61063f
commit 40513cc488
3 changed files with 18 additions and 7 deletions

View File

@ -69,6 +69,17 @@ def select_all_frames(conn):
rows = cur.fetchall() rows = cur.fetchall()
return rows return rows
def select_all_stations(conn):
"""
Query all rows in the stations table
:param conn: the Connection object
:return:
"""
cur = conn.cursor()
cur.execute("SELECT * FROM stations ORDER BY last_heard_unix DESC")
rows = cur.fetchall()
return rows
def unique_stations(conn): def unique_stations(conn):
""" """
Query all rows in the frames table Query all rows in the frames table
@ -109,7 +120,7 @@ def index():
response = json.loads(requests.get("https://digi.w1cdn.net/aprs_api/packets").text)['data'] response = json.loads(requests.get("https://digi.w1cdn.net/aprs_api/packets").text)['data']
# Play with function to create station list # Play with function to create station list
stations = unique_stations(get_db_connection()) stations = select_all_stations(get_db_connection())
return render_template('index.html', return render_template('index.html',
station_call = config['Settings']['station_call'], station_call = config['Settings']['station_call'],

View File

@ -29,6 +29,7 @@ def main():
ki = aprs.TCPKISS(host=config['Settings']['kiss_host'], port=int(config['Settings']['kiss_port'])) ki = aprs.TCPKISS(host=config['Settings']['kiss_host'], port=int(config['Settings']['kiss_port']))
ki.start() ki.start()
# Make a simple frame and send it # Make a simple frame and send it
frame = aprs.APRSFrame.ui( frame = aprs.APRSFrame.ui(
destination="APZ001", destination="APZ001",
@ -72,6 +73,7 @@ def main():
# It's not immediately needed, so I'm skipping it. # It's not immediately needed, so I'm skipping it.
# Build query # Build query
# "from" is wrappedin [] because it is a reserved word and using '' doesn't work. # "from" is wrappedin [] because it is a reserved word and using '' doesn't work.
# https://www.sqlite.org/lang_keywords.html
try: try:
station_update = "'"+a['from'] +"', '"+ str(a['created_unix']) +"', '1'" station_update = "'"+a['from'] +"', '"+ str(a['created_unix']) +"', '1'"
query3 = "INSERT INTO stations ([from], last_heard_unix, count) \ query3 = "INSERT INTO stations ([from], last_heard_unix, count) \

View File

@ -11,10 +11,10 @@
</style> </style>
</head> </head>
<body> <body>
<h1>{{station_call}} Status</h1> <h1>{{station_call}} Status</h1>
{{station_lat}}, {{station_lon}} {{station_lat}}, {{station_lon}}
<h3> Recent RF Packets </h3> <h2> Recent RF Packets </h2>
<table> <table>
<tr> <tr>
<th> from </th> <th> from </th>
@ -36,8 +36,6 @@
</table> </table>
<h2> Recent Stations </h2> <h2> Recent Stations </h2>
Coming soon, see <a href="https://amiok.net/gitea/W1CDN/aprs_tool/issues/16">https://amiok.net/gitea/W1CDN/aprs_tool/issues/16</a>.
<table> <table>
<tr> <tr>
<th> from </th> <th> from </th>
@ -48,8 +46,8 @@ Coming soon, see <a href="https://amiok.net/gitea/W1CDN/aprs_tool/issues/16">htt
{% for i in stations %} {% for i in stations %}
<tr> <tr>
<td> <a href="https://digi.w1cdn.net/aprs_api/packets?from={{ i['from'] }}">{{ i['from'] }}</a> </td> <td> <a href="https://digi.w1cdn.net/aprs_api/packets?from={{ i['from'] }}">{{ i['from'] }}</a> </td>
<td> {{ i['created'] }} </td> <td> {{ i['last_heard_unix'] }} </td>
<td> {{ i['COUNT(id)']}} </td> <td> {{ i['count']}} </td>
<td> <a href="https://aprs.fi/#!mt=roadmap&z=12&call=a%2F{{ i['from'] }}">aprs.fi</a></td> <td> <a href="https://aprs.fi/#!mt=roadmap&z=12&call=a%2F{{ i['from'] }}">aprs.fi</a></td>
</tr> </tr>
{% endfor %} {% endfor %}