diff --git a/address_finder/api.py b/address_finder/api.py index 7409822..b69a4c4 100644 --- a/address_finder/api.py +++ b/address_finder/api.py @@ -54,7 +54,7 @@ class AddressFinder: print("Error querying DB : {0}".format(err), file=sys.stderr) return [] - communesMap=dict() + communesMap = dict() for row in cur.fetchall(): row_obj = dict(row) commune = Commune( @@ -62,12 +62,12 @@ class AddressFinder: nom=row_obj[DB_COL_COMMUNE_NAME], codeZip=row_obj[DB_COL_COMMUNE_POSTE]) # This way we avoid duplicates - communesMap[commune["codeInsee"]]= commune + communesMap[commune["codeInsee"]] = commune con.close() return list(communesMap.values()) - def getCommuneFantoirVoies(self, communeInseeCode: str) -> list[FantoirVoie]: + def getCommuneFantoirVoies(self, communeInseeCode: str, voieSearch: str = None) -> list[FantoirVoie]: # Extract data from DB con = sqlite3.connect(self.dbPath) @@ -92,6 +92,19 @@ class AddressFinder: data_dict = json.loads(data.get("value")) # In extracted JSON data, the interesting payload is behind "value" key fantoir_dict = data_dict.get("value") + if voieSearch is not None: + regexSearch = r".*" + for expr in voieSearch.split(' '): + regexSearch += r"(?=" + expr + r").*" + regexSearch += r".*" + fantoir_voies_filtered = [] + for voie in fantoir_dict: + for libelle in voie['libelle']: + if re.search(regexSearch, libelle, re.IGNORECASE): + fantoir_voies_filtered.append(voie) + break + fantoir_dict = fantoir_voies_filtered + else: print("Did not found any data matching Insee code " + str(communeInseeCode)) diff --git a/templates/landing_form.html b/templates/landing_form.html index c2bcc1b..e6b0c1a 100644 --- a/templates/landing_form.html +++ b/templates/landing_form.html @@ -25,10 +25,10 @@

Test d'éligibilité par PTO

-
+
- + Où trouver mon numéro de PTO ?
@@ -49,25 +49,27 @@

Test d'éligibilité par adresse

- +
- +
-
+
- +
- + + +

- +
@@ -79,6 +81,9 @@ diff --git a/webapp.py b/webapp.py index f87ab70..31d61bc 100644 --- a/webapp.py +++ b/webapp.py @@ -48,9 +48,25 @@ def get_communes(): @app.route("/addresses/fantoirvoies/", methods=['GET']) def get_fantoir_voies(codeInsee): - fantoirVoies=addressFinder.getCommuneFantoirVoies(codeInsee) + to_search=request.args.get('s') + fantoirVoies=addressFinder.getCommuneFantoirVoies(codeInsee,to_search) response = app.response_class( response=json.dumps(fantoirVoies), mimetype='application/json' ) - return response \ No newline at end of file + return response + +@app.route("/test/address", methods=['POST']) +def test_address(): + print(request.form) + # pto = escape(request.form['pto']) + # result = parse_response(query_axione_pto(cfg, pto)) + return json.dumps({'success':True}), 200, {'ContentType':'application/json'} + + +@app.route("/test/pto", methods=['POST']) +def test_pto(): + print(request.form) + # pto = escape(request.form['pto']) + # result = parse_response(query_axione_pto(cfg, pto)) + return json.dumps({'success':True}), 200, {'ContentType':'application/json'}