-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
38 lines (24 loc) · 1.01 KB
/
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
33
34
35
36
37
38
from flask import Flask, jsonify, send_from_directory, render_template
import geopandas as gpd
import os
app = Flask(__name__)
# Load the shapefile
shapefile_path = "./assets/boundaries/PCON_DEC_2019_UK_BFC.shp"
gdf = gpd.read_file(shapefile_path)
gdf = gdf.to_crs(epsg=4326)
@app.route('/info')
def get_info():
row = gdf.sample(n=1)
random_point = row.geometry.sample_points(size=1).tolist()[0]
random_coordinates = {'lat': random_point.y, 'lng': random_point.x}
winner = row["winner"].tolist()[0]
party_dict = {"Con":"Conservative", "Lab":"Labour", "SNP":"SNP", "LD":"Liberal Democrats", "DUP":"DUP",
"SF":"Sinn Fein", "PC":"Plaid Cymru", "SDLP":"SDLP", "Green":"Green", "Spk":"Other", "Alliance":"Alliance"}
winner = party_dict[winner]
name = row["PCON19NM"].tolist()[0]
return {"coords":random_coordinates, "winner":winner, "const_name":name}
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)