From 01c8f2b37bb4d12dabfc50838a9580c9ce52964e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Baylac-Jacqu=C3=A9?= Date: Sat, 12 Feb 2022 18:31:40 +0100 Subject: [PATCH] Fantoir: implement actual Axione fantoir request Kind of untested :/ --- axione_api/api.py | 25 +++++++++++++++++++++++++ webapp.py | 6 ++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/axione_api/api.py b/axione_api/api.py index 492844f..5508265 100644 --- a/axione_api/api.py +++ b/axione_api/api.py @@ -23,9 +23,34 @@ def ptoRequest(ptoRef): """ +def fantoirRequest(insee, rivoli, numVoie): + ts = datetime.now(timezone.utc).isoformat() + return f""" + + + + + + + + + + + + + + """ + +def query_axione_fantoir(cfg, insee, rivoli, numVoie): + body = fantoirRequest(insee, rivoli, numVoie) + query_axione(cfg, body) + def query_axione_pto(cfg, ptoRef): body = ptoRequest(ptoRef) + query_axione(cfg, body) + +def query_axione(cfg, body): # Note: the password should be the base64 of username:password. # Don't ask why. passwd = base64.b64encode(f"{cfg.username}:{cfg.password}".encode("utf8")).decode( diff --git a/webapp.py b/webapp.py index 3a5ecdf..f732c0a 100644 --- a/webapp.py +++ b/webapp.py @@ -56,9 +56,11 @@ def get_fantoir_voies(codeInsee): def test_address(): commune = escape(request.form['commune']) numeroVoie = escape(request.form['numeroVoie']) - voie = escape(request.form['voie']) + # 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 json.dumps({'success':True}), 200, {'ContentType':'application/json'} + return render_template("result.html", pto="", result=result) @app.route("/test/pto", methods=['POST'])