59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
from flask import Flask, request, render_template
|
|
|
|
from typing import TypedDict
|
|
import configparser
|
|
import sqlite3
|
|
import os
|
|
from ipe_fetcher import Liazo,Axione,Arcep
|
|
class Config(TypedDict):
|
|
axione_ipe_path: str
|
|
|
|
|
|
def parseConfig() -> Config:
|
|
cfg_path = os.environ.get("CONFIG", "/etc/ftth-ipe-map/conf.ini")
|
|
cfg = configparser.ConfigParser()
|
|
with open(cfg_path, "r") as f:
|
|
cfg.read_file(f)
|
|
return {
|
|
"axione_ipe_path": cfg.get("DB", "axione_ipe_path"),
|
|
"axione_ipe_path": cfg.get("DB", "axione_ipe_path"),
|
|
}
|
|
|
|
|
|
app = Flask(__name__)
|
|
cfg: Config = parseConfig()
|
|
|
|
axione = Axione(cfg.get("axione_ipe_path"), "ipe")
|
|
arcep = Arcep()
|
|
liazo = Liazo()
|
|
|
|
|
|
@app.route("/", methods=["GET"])
|
|
def getMap():
|
|
return render_template("map.html")
|
|
|
|
|
|
@app.route("/eligdata", methods=["GET"])
|
|
def getEligData():
|
|
args = request.args
|
|
valid_args = True
|
|
processed_args = {}
|
|
for k in ["swx", "swy", "nex", "ney", "centerlat", "centerlng"]:
|
|
valid_args = valid_args and k in args
|
|
if valid_args:
|
|
try:
|
|
processed_args[k] = float(args[k])
|
|
except ValueError:
|
|
valid_args = False
|
|
if valid_args:
|
|
buildings = dict()
|
|
try:
|
|
buildings = axione.getAreaBuildings(processed_args, buildings)
|
|
except ValueError as err:
|
|
print("Could not get Axione data for this area:", err)
|
|
|
|
buildings = liazo.getAreaBuildings(processed_args["centerlat"], processed_args["centerlng"], buildings)
|
|
|
|
return {"buildings": buildings}
|
|
else:
|
|
return "Invalid bounding box coordinates", 400
|