############################################################################### # HBLink - Copyright (C) 2020 Cortney T. Buffington, N0MJS # GPS/Data - Copyright (C) 2020 Eric Craw, KF7EEL # # 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, request, Response, Markup import ast, os from dashboard_settings import * import folium from folium.plugins import MarkerCluster import re app = Flask(__name__) tbl_hdr = ''' ''' tbl_ftr = '''
''' def get_loc_data(): try: dash_loc = ast.literal_eval(os.popen('cat /tmp/gps_data_user_loc.txt').read()) tmp_loc = '' loc_hdr = '''

 Callsign 

 Latitude 

 Longitude 

 Local Time 

''' last_known_loc_list = [] display_number = 15 for e in dash_loc: if display_number == 0: break else: if e['call'] in last_known_loc_list: pass if e['call'] not in last_known_loc_list: last_known_loc_list.append(e['call']) display_number = display_number - 1 tmp_loc = tmp_loc + ''' ''' + e['call'] + '''  ''' + str(e['lat']) + '''   ''' + str(e['lon']) + '''   ''' + e['time'] + '''  ''' return str(str('

Last Known Location

') + tbl_hdr + loc_hdr + tmp_loc + tbl_ftr) except: return str('

No data

') def get_bb_data(): try: dash_bb = ast.literal_eval(os.popen('cat /tmp/gps_data_user_bb.txt').read()) tmp_bb = '' bb_hdr = '''

 Callsign 

 DMR ID 

 Bulletin 

 Local Time 

''' for e in dash_bb: tmp_bb = tmp_bb + '''  ''' + e['call'] + '''  ''' + str(e['dmr_id']) + '''  ''' + e['bulletin'] + '''   ''' + e['time'] + '''  ''' return str('

Bulletin Board

' + tbl_hdr + bb_hdr + tmp_bb + tbl_ftr) except: return str('

No data

') def check_emergency(): # open emergency txt try: sos_file = ast.literal_eval(os.popen('cat /tmp/gps_data_user_sos.txt').read()) if '@NOTICE' in sos_file['message'] and '@SOS' not in sos_file['message']: notice_header = 'NOTICE:' else: notice_header = 'EMERGENCY ACTIVATION' value = Markup("""

""" + notice_header + """

 

From: """ + sos_file['call'] + """ - """ + str(sos_file['dmr_id']) + """
Message: """ + sos_file['message'] + """
Time: """ + sos_file['time'] + """

 

View on aprs.fi


""") return value except: return '' def aprs_to_latlon(x): degrees = int(x) // 100 minutes = x - 100*degrees return degrees + minutes/60 @app.route('/') def index(): value = Markup('The HTML String') #return get_data() return render_template('index.html', title = dashboard_title, logo = logo, emergency = check_emergency()) @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() @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) @app.route('/view_map') def view_map(): reload_time = request.args.get('reload') track_call = request.args.get('track') user_loc = ast.literal_eval(os.popen('cat /tmp/gps_data_user_loc.txt').read()) last_known_list = [] try: if track_call: #folium_map = folium.Map(location=map_center, zoom_start=int(zoom_level)) #marker_cluster = MarkerCluster().add_to(folium_map) for user_coord in user_loc: user_lat = aprs_to_latlon(float(re.sub('[A-Za-z]','', user_coord['lat']))) user_lon = aprs_to_latlon(float(re.sub('[A-Za-z]','', user_coord['lon']))) if 'S' in user_coord['lat']: user_lat = -user_lat if 'W' in user_coord['lon']: user_lon = -user_lon if user_coord['call'] not in last_known_list and user_coord['call'] == track_call: folium_map = folium.Map(location=[user_lat, user_lon], tiles="Stamen Toner", zoom_start=15) marker_cluster = MarkerCluster().add_to(folium_map) folium.Marker([user_lat, user_lon], popup="""
Last Location:
"""+ str(user_coord['call']) +"""
"""+ user_coord['time'] +"""
""", icon=folium.Icon(color="red", icon="record"), tooltip=str(user_coord['call'])).add_to(folium_map) last_known_list.append(user_coord['call']) if user_coord['call'] in last_known_list and user_coord['call'] == track_call: folium.CircleMarker([user_lat, user_lon], popup="""
""" + user_coord['call'] + """
""" + user_coord['time'] + """
""", tooltip=str(user_coord['call']), fill=True, fill_color="#3186cc", radius=4).add_to(marker_cluster) #return folium_map._repr_html_() if not reload_time: reload_time = 120 return '{} {}'.format(''' """ + dashboard_title + """ - Tracking """+ track_call + """

""" + dashboard_title + """ - Tracking """ + track_call + """

Page automatically reloads every """ + str(reload_time) + """ seconds.

""", folium_map._repr_html_()) except: return """

Station not found.

""" if not track_call: folium_map = folium.Map(location=map_center, tiles="Stamen Toner", zoom_start=int(zoom_level)) marker_cluster = MarkerCluster().add_to(folium_map) for user_coord in user_loc: user_lat = aprs_to_latlon(float(re.sub('[A-Za-z]','', user_coord['lat']))) user_lon = aprs_to_latlon(float(re.sub('[A-Za-z]','', user_coord['lon']))) if 'S' in user_coord['lat']: user_lat = -user_lat if 'W' in user_coord['lon']: user_lon = -user_lon if user_coord['call'] not in last_known_list: folium.Marker([user_lat, user_lon], popup="""
Last Location:
""" + user_coord['call'] + """
""" + user_coord['time'] + """
Track Station
""", icon=folium.Icon(color="red", icon="record"), tooltip=str(user_coord['call'])).add_to(folium_map) last_known_list.append(user_coord['call']) if user_coord['call'] in last_known_list: folium.CircleMarker([user_lat, user_lon], popup="""
""" + user_coord['call'] + """
""" + user_coord['time'] + """
""", tooltip=str(user_coord['call']), fill=True, fill_color="#3186cc", radius=4).add_to(marker_cluster) return folium_map._repr_html_() @app.route('/map/') def map(): return render_template('map.html', title = dashboard_title, logo = logo) @app.route('/bulletin_rss.xml') def bb_rss(): try: dash_bb = ast.literal_eval(os.popen('cat /tmp/gps_data_user_bb.txt').read()) post_data = '' rss_header = """ """ + dashboard_title + """ - Bulletin Board Feed """ + rss_link + """ This is the Bulletin Board feed from """ + dashboard_title + """""" for entry in dash_bb: post_data = post_data + """ """ + entry['call'] + ' - ' + str(entry['dmr_id']) + """ """ + rss_link + """ """ + entry['bulletin'] + """ - """ + entry['time'] + """ """ return Response(rss_header + post_data + "\n\n", mimetype='text/xml') except: return str('

No data

') if __name__ == '__main__': app.run(debug = True, port=dash_port, host=dash_host)