DAPRS/dashboard/dashboard.py
2022-12-02 13:27:53 +01:00

132 lines
5.0 KiB
Python

###############################################################################
# HBLink - Copyright (C) 2020 Cortney T. Buffington, N0MJS <n0mjs@me.com>
# GPS/Data - Copyright (C) 2020 Eric Craw, KF7EEL <kf7eel@qsl.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
###############################################################################
'''
This is a web dashboard for the GPS/Data application.
'''
from flask import Flask, render_template
import ast, os
from dashboard_settings import *
app = Flask(__name__)
tbl_hdr = '''
<fieldset style="border-radius: 8px; background-color:#e0e0e0e0; text-algin: lef; margin-left:15px;margin-right:15px;font-size:14px;border-top-left-radius: 10px; border-top-right-radius: 10px;border-bottom-left-radius: 10px; border-bottom-right-radius: 10px;">
<table style="width:100%; font: 10pt arial, sans-serif">
'''
tbl_ftr = '''
</table></fieldset>
'''
def get_loc_data():
try:
dash_loc = ast.literal_eval(os.popen('cat /tmp/gps_data_user_loc.txt').read())
tmp_loc = ''
loc_hdr = '''
<TR style=" height: 32px;font: 10pt arial, sans-serif; background-color:#CDCDCD; color:black">
<TH>Indicatif</TH><TH>Latitude</TH><TH>Longitude</TH><TH>Date et heure</TH></TR>
'''
cpt=0
for e in dash_loc:
cpt = cpt + 1
tmp_color="#f9f9f9f9"
if cpt >= 2:
tmp_color="#d9d9d9d9"
cpt = 0
tmp_loc = tmp_loc + '''
<TR style="background-color:''' + str(tmp_color) + ''';">
<TD><strong>''' + e['call'] + '''</strong></TD>
<TD><strong>&nbsp;''' + str(e['lat']) + '''&nbsp;</strong></TD>
<TD><strong>&nbsp;''' + str(e['lon']) + '''&nbsp;</strong></TD>
<TD>&nbsp;''' + e['time'] + '''&nbsp;</TD>
</TR>
'''
return str(str('<h1 style="text-align: center;">Positions Reçues</h1>') + tbl_hdr + loc_hdr + tmp_loc + tbl_ftr)
except:
return str('<h1 style="text-align: center;">Pas de données</h1>')
def get_log_data():
#try:
dash_log = (os.popen('cat /tmp/gps_data.log | nl | sort -n -r | cut -f2').read())
dash_log = dash_log.replace('\n', '<br>')
return str('<font color="#fff">'+dash_log+'</font>')
#except:
# return str('<font color="#fff">Pas de données</font>')
def get_bb_data():
try:
dash_bb = ast.literal_eval(os.popen('cat /tmp/gps_data_user_bb.txt').read())
tmp_bb = ''
bb_hdr = '''
<TR style=" height: 32px;font: 10pt arial, sans-serif; background-color:#CDCDCD; color:black">
<TH>Indicatif</TH><TH>DMR id</TH><TH>Bulletin</TH><TH>Date et heure</TH></TR>
'''
for e in dash_bb:
tmp_bb = tmp_bb + '''
<TR style="background-color:#f9f9f9f9;">
<TD><strong>&nbsp;''' + e['call'] + '''&nbsp;</strong></TD>
<TD>''' + str(e['dmr_id']) + '''</TD>
<TD><strong>&nbsp;''' + e['bulliten'] + '''&nbsp;</strong></TD>
<TD>&nbsp;''' + e['time'] + '''&nbsp;</TD>
</TR>
'''
return str('<h1 style="text-align: center;">Bulletins</h1>' + tbl_hdr + bb_hdr + tmp_bb + tbl_ftr)
except:
return str('<h1 style="text-align: center;">No data</h1>')
@app.route('/')
def index():
#return get_data()
return render_template('index.html', title = dashboard_title, logo = logo)
@app.route('/bulletin_board')
def dash_bb():
return get_bb_data()
#return render_template('index.html', data = str(get_data()))
@app.route('/positions')
def dash_loc():
return get_loc_data()
#return render_template('index.html', data = str(get_data()))
@app.route('/logdaprs')
def dash_log():
return get_log_data()
##@app.route('/<string:page_name>/')
##def render_static(page_name):
## return render_template('%s.html' % page_name, title = dashboard_title, logo = logo, description = description)
@app.route('/help/')
def help():
#return get_data()
return render_template('help.html', title = dashboard_title, logo = logo, description = description, data_call_type = data_call_type, data_call_id = data_call_id, aprs_ssid = aprs_ssid)
@app.route('/about/')
def about():
#return get_data()
return render_template('about.html', title = dashboard_title, logo = logo, contact_name = contact_name, contact_call = contact_call, contact_email = contact_email, contact_website = contact_website)
if __name__ == '__main__':
app.run(debug = True, port=dash_port, host=dash_host)