01c8f2b37b
Kind of untested :/
70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
import os
|
|
from flask import Flask, render_template, request, escape
|
|
import json
|
|
|
|
from config.config import parse_config
|
|
from axione_api.api import query_axione_pto, parse_response
|
|
from address_finder.api import AddressFinder
|
|
|
|
def load_config():
|
|
cfg_path = os.environ.get("CONFIG", "/etc/ftth-elig/conf.ini")
|
|
print(f'Reading the "{cfg_path}" config file')
|
|
cfg = parse_config(cfg_path)
|
|
cfg.debug = True if "DEBUG" in os.environ else False
|
|
if cfg.debug:
|
|
print("===================")
|
|
print("DEBUG_MODE")
|
|
print("No requests will be performed")
|
|
print("We'll inject some dummy data instead")
|
|
print("===================")
|
|
print("")
|
|
return cfg
|
|
|
|
cfg = load_config()
|
|
|
|
addressFinder = AddressFinder(cfg.db_addresses_sqlite_path)
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route("/", methods=['GET'])
|
|
def get_form():
|
|
return render_template("landing_form.html")
|
|
|
|
@app.route("/addresses/communes", methods=['GET'])
|
|
def get_communes():
|
|
to_search=request.args.get('s')
|
|
limit=request.args.get('limit')
|
|
communes=addressFinder.getCommunesFromNameOrZip(to_search,limit)
|
|
response = app.response_class(
|
|
response=json.dumps(communes),
|
|
mimetype='application/json'
|
|
)
|
|
return response
|
|
|
|
@app.route("/addresses/fantoirvoies/<codeInsee>", methods=['GET'])
|
|
def get_fantoir_voies(codeInsee):
|
|
to_search=request.args.get('s')
|
|
limit=request.args.get('limit')
|
|
fantoirVoies=addressFinder.getCommuneFantoirVoies(codeInsee,to_search,limit)
|
|
response = app.response_class(
|
|
response=json.dumps(fantoirVoies),
|
|
mimetype='application/json'
|
|
)
|
|
return response
|
|
|
|
@app.route("/test/address", methods=['POST'])
|
|
def test_address():
|
|
commune = escape(request.form['commune'])
|
|
numeroVoie = escape(request.form['numeroVoie'])
|
|
# Trimming rivoli's key
|
|
voie = escape(request.form['voie'])[:-1]
|
|
result = query_axione_fantoir(cfg, commune, voie, numeroVoie)
|
|
# result = parse_response(query_axione_pto(cfg, pto))
|
|
return render_template("result.html", pto="", result=result)
|
|
|
|
|
|
@app.route("/test/pto", methods=['POST'])
|
|
def test_pto():
|
|
pto = escape(request.form['pto'])
|
|
result = parse_response(query_axione_pto(cfg, pto))
|
|
return render_template("result.html", pto=pto, result=result)
|