forked from 12v/boundary-bubbler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
32 lines (27 loc) · 1007 Bytes
/
app.py
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
from flask import Flask, render_template, send_from_directory
import csv
import os
app = Flask(__name__)
def load_statistics():
statistics = []
with open('output/wards/statistics.csv', 'r') as f:
reader = csv.DictReader(f)
for row in reader:
if row['name'] and row['coverage']: # Skip empty rows and summary stats
statistics.append({
'name': row['name'],
'coverage': float(row['coverage'])
})
return sorted(statistics, key=lambda x: x['name'])
@app.route('/')
def index():
statistics = load_statistics()
return render_template('index.html', constituencies=statistics)
@app.route('/images/<path:filename>')
def serve_image(filename):
return send_from_directory('output/wards/JPGs', filename + '.jpg')
if __name__ == '__main__':
# Create templates directory if it doesn't exist
if not os.path.exists('templates'):
os.makedirs('templates')
app.run(debug=True)