This repository was archived by the owner on Dec 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py.old
More file actions
130 lines (105 loc) · 4.05 KB
/
app.py.old
File metadata and controls
130 lines (105 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from flask import Flask, render_template, request, jsonify
import json
import os
ASSETS_DIR = 'assets'
app = Flask(__name__, static_folder=ASSETS_DIR, template_folder='templates')
# Load data files
def load_json_data(filename):
"""Load JSON data from the assets/data directory"""
try:
with open(os.path.join(ASSETS_DIR, "data", filename), 'r') as f:
return json.load(f)
except FileNotFoundError:
return {}
def get_data():
"""Load all data files"""
config = load_json_data('config.json')
nodes_data = load_json_data('nodes.json')
members_data = load_json_data('members.json')
# Filter public nodes and members
nodes = [node for node in nodes_data.get('nodes', []) if node.get('isPublic', True)]
members = [member for member in members_data.get('members', []) if member.get('isPublic', True)]
return config, nodes, members
@app.route('/')
def home():
"""Home page"""
config, nodes, members = get_data()
# Calculate stats
stats = {
'totalNodes': len(nodes),
'totalMembers': len(members),
'coverageArea': calculate_coverage_area(nodes)
}
return render_template('index.html', config=config, nodes=nodes, members=members, stats=stats)
@app.route('/<area>/<node_id>')
def redirect_to_nodes(area, node_id):
"""Redirect short URL format to full nodes URL"""
from flask import redirect, url_for
return redirect(url_for('nodes', area=area, node_id=node_id), code=301)
@app.route('/nodes/')
@app.route('/nodes/<area>/<node_id>')
def nodes(area=None, node_id=None):
"""Nodes page with optional individual node view"""
config, nodes, members = get_data()
current_node = None
if area and node_id:
# Find the specific node
full_node_id = f"{node_id}.{area}.ipnt.uk"
current_node = next((node for node in nodes if node['id'] == full_node_id or node['id'] == node_id), None)
# Calculate node statistics for list view
node_stats = None
if not current_node:
node_stats = {
'totalNodes': len(nodes),
'onlineNodes': len([node for node in nodes if node.get('isOnline', True)]),
'repeaterNodes': len([node for node in nodes if node.get('meshRole') == 'repeater'])
}
return render_template('nodes.html',
config=config,
nodes=nodes,
members=members,
current_node=current_node,
showing_individual_node=current_node is not None,
node_stats=node_stats)
@app.route('/members/')
def members():
"""Members page"""
config, nodes, members_list = get_data()
return render_template('members.html', config=config, nodes=nodes, members=members_list)
@app.route('/contact/')
def contact():
"""Contact page"""
config, nodes, members = get_data()
return render_template('contact.html', config=config)
@app.route('/api/data')
def api_data():
"""API endpoint to serve data as JSON"""
config, nodes, members = get_data()
return jsonify({
'config': config,
'nodes': nodes,
'members': members
})
def calculate_coverage_area(nodes):
"""Calculate approximate coverage area in km²"""
if not nodes:
return 0
# Extract coordinates
coords = []
for node in nodes:
if node.get('location') and node['location'].get('lat') and node['location'].get('lng'):
coords.append((node['location']['lat'], node['location']['lng']))
if not coords:
return 0
# Simple bounding box calculation
lats = [coord[0] for coord in coords]
lngs = [coord[1] for coord in coords]
min_lat, max_lat = min(lats), max(lats)
min_lng, max_lng = min(lngs), max(lngs)
# Rough approximation of area in km²
lat_diff = max_lat - min_lat
lng_diff = max_lng - min_lng
area = round(lat_diff * lng_diff * 12400) # Rough conversion factor
return max(area, 50) # Minimum 50 km²
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)