2022-02-21 17:21:21 +01:00
|
|
|
from flask import Flask, request, render_template
|
2022-02-21 15:28:19 +01:00
|
|
|
|
2022-02-22 12:48:50 +01:00
|
|
|
from typing import TypedDict
|
|
|
|
import configparser
|
|
|
|
import sqlite3
|
|
|
|
import os
|
2022-03-23 22:54:04 +01:00
|
|
|
from ipe_fetcher import Liazo,Axione
|
2022-02-22 12:48:50 +01:00
|
|
|
class Config(TypedDict):
|
2022-03-23 22:54:04 +01:00
|
|
|
axione_ipe_path: str
|
|
|
|
|
2022-02-22 12:48:50 +01:00
|
|
|
|
|
|
|
def parseConfig() -> Config:
|
2022-03-23 22:54:04 +01:00
|
|
|
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")}
|
|
|
|
|
2022-02-22 12:48:50 +01:00
|
|
|
|
2022-02-21 15:28:19 +01:00
|
|
|
app = Flask(__name__)
|
2022-03-23 22:54:04 +01:00
|
|
|
cfg: Config = parseConfig()
|
|
|
|
|
|
|
|
axione = Axione(cfg.get("axione_ipe_path"))
|
|
|
|
liazo = Liazo()
|
|
|
|
|
2022-02-21 15:28:19 +01:00
|
|
|
|
2022-02-22 12:48:50 +01:00
|
|
|
@app.route("/", methods=["GET"])
|
2022-02-21 15:28:19 +01:00
|
|
|
def getMap():
|
|
|
|
return render_template("map.html")
|
2022-02-21 17:21:21 +01:00
|
|
|
|
2022-03-23 22:54:04 +01:00
|
|
|
|
2022-02-22 12:48:50 +01:00
|
|
|
@app.route("/eligdata", methods=["GET"])
|
2022-02-21 17:21:21 +01:00
|
|
|
def getEligData():
|
|
|
|
args = request.args
|
2022-02-22 12:48:50 +01:00
|
|
|
valid_args = True
|
|
|
|
processed_args = {}
|
2022-03-23 22:54:04 +01:00
|
|
|
for k in ["swx", "swy", "nex", "ney", "centerlat", "centerlng"]:
|
2022-02-22 12:48:50 +01:00
|
|
|
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:
|
2022-03-23 22:54:04 +01:00
|
|
|
buildings = dict()
|
|
|
|
try:
|
|
|
|
buildings = axione.getAreaBuildings(processed_args, buildings)
|
|
|
|
except ValueError as err:
|
|
|
|
print("Could not get Axione data for this area:", err)
|
|
|
|
|
2022-04-11 09:49:51 +02:00
|
|
|
# buildings = liazo.getAreaBuildings(processed_args["centerlat"], processed_args["centerlng"], buildings)
|
2022-03-23 22:54:04 +01:00
|
|
|
|
|
|
|
return {"buildings": buildings}
|
2022-02-21 17:21:21 +01:00
|
|
|
else:
|
2022-02-22 12:48:50 +01:00
|
|
|
return "Invalid bounding box coordinates", 400
|