Fantoir: implement actual Axione fantoir request

Kind of untested :/
This commit is contained in:
Félix Baylac-Jacqué 2022-02-12 18:31:40 +01:00
parent 3acd1dd349
commit 01c8f2b37b
2 changed files with 29 additions and 2 deletions

View file

@ -23,9 +23,34 @@ def ptoRequest(ptoRef):
</soapenv:Envelope> </soapenv:Envelope>
""" """
def fantoirRequest(insee, rivoli, numVoie):
ts = datetime.now(timezone.utc).isoformat()
return f"""
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ent="http://structureadresseftth.axione.fr/model/entreprise" xmlns:com="http://structureadresseftth.axione.fr/model/commun">
<soapenv:Header/>
<soapenv:Body>
<ent:obtentionStructureAdresseDemandeSoap>
<ent:entete versionWS="3.0" horodatageRequete="{ts}">
<com:operateurCommercial nom="AQUILENET" identifiant=""/>
</ent:entete>
<ent:referenceAdresse>
<com:referenceRivoli codeInsee="{insee}" codeRivoli="{rivoli}" numeroVoie="{numvoie}"/>
</ent:referenceAdresse>
</ent:obtentionStructureAdresseDemandeSoap>
</soapenv:Body>
</soapenv:Envelope>
"""
def query_axione_fantoir(cfg, insee, rivoli, numVoie):
body = fantoirRequest(insee, rivoli, numVoie)
query_axione(cfg, body)
def query_axione_pto(cfg, ptoRef): def query_axione_pto(cfg, ptoRef):
body = ptoRequest(ptoRef) body = ptoRequest(ptoRef)
query_axione(cfg, body)
def query_axione(cfg, body):
# Note: the password should be the base64 of username:password. # Note: the password should be the base64 of username:password.
# Don't ask why. # Don't ask why.
passwd = base64.b64encode(f"{cfg.username}:{cfg.password}".encode("utf8")).decode( passwd = base64.b64encode(f"{cfg.username}:{cfg.password}".encode("utf8")).decode(

View file

@ -56,9 +56,11 @@ def get_fantoir_voies(codeInsee):
def test_address(): def test_address():
commune = escape(request.form['commune']) commune = escape(request.form['commune'])
numeroVoie = escape(request.form['numeroVoie']) 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)) # 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']) @app.route("/test/pto", methods=['POST'])