diff --git a/data-ingest/ingest b/data-ingest/ingest index 13578e9..67c438e 100755 --- a/data-ingest/ingest +++ b/data-ingest/ingest @@ -23,12 +23,29 @@ cat > "${tmpSql}" <> "${tmpSql}" <> "${tmpSql}" < "${tmpSql}" < "${tmpSql}" < dict: @@ -59,11 +74,13 @@ class Axione: """, areaCoordinates, ) - + + res = cur.fetchall() + if not existing_buildings: existing_buildings = dict() buildings = existing_buildings - for b in cur.fetchall(): + for b in res: etatImm = b[3] idImm = b[2] isEligible = etatImm == AXIONE_ETAT_DEPLOYE @@ -99,3 +116,37 @@ class Axione: return buildings else: raise ValueError("The requested area is too wide, please reduce it") + + def get_eligibilite_per_id_immeuble(self, id_immeuble: str): + + # Try to get cursor on Axione database + try: + cur = getBasicCursor(self.db_axione_ipe_path) + except Exception as err: + print("Error while connecting to DB: ", err) + raise "Could not get Axione data" + + cur.execute( + f""" + SELECT EtatImmeuble + FROM {self.db_name_refimm} + WHERE IdentifiantImmeuble == '{id_immeuble}' + """ + ) + res = cur.fetchone() + if res: + imm_elig = res[0] + isEligible = imm_elig == AXIONE_ETAT_DEPLOYE + reasonNotEligible = "" if isEligible else "Pas encore deploye" + else: + isEligible = False + imm_elig = "NOT_AXIONE" + reasonNotEligible = "Axione ne gere pas ce batiment" + + eligStatus = FAIEligibilityStatus( + isEligible=isEligible, + ftthStatus=imm_elig, + reasonNotEligible=reasonNotEligible, + ) + + return eligStatus diff --git a/webapp/ipe_fetcher/sqlite_connector/cursor.py b/webapp/ipe_fetcher/sqlite_connector/cursor.py index b41527f..a7701ed 100644 --- a/webapp/ipe_fetcher/sqlite_connector/cursor.py +++ b/webapp/ipe_fetcher/sqlite_connector/cursor.py @@ -6,3 +6,8 @@ def getCursorWithSpatialite(db_path: str = None) -> sqlite3.Cursor: db.enable_load_extension(True) cur.execute('SELECT load_extension("mod_spatialite")') return cur + +def getBasicCursor(db_path: str = None) -> sqlite3.Cursor: + db = sqlite3.connect(db_path) + cur = db.cursor() + return cur diff --git a/webapp/main.py b/webapp/main.py index 3297793..42fe7a5 100644 --- a/webapp/main.py +++ b/webapp/main.py @@ -5,6 +5,10 @@ import configparser import sqlite3 import os from ipe_fetcher import Liazo,Axione,Arcep,AreaCoordinates +from eligibility_api.elig_api_exceptions import FlaskExceptions +from eligibility_api.elig_api_routes import EligibilityApiRoutes + + class Config(TypedDict): axione_ipe_path: str axione_ipe_db_name: str @@ -31,7 +35,10 @@ cfg: Config = parseConfig() axione = Axione(cfg.get("axione_ipe_path"), cfg.get("axione_ipe_db_name")) arcep = Arcep(cfg.get("arcep_ipe_path"), cfg.get("arcep_ipe_db_name")) liazo = Liazo() - +elig_api_routes = EligibilityApiRoutes(app, axione) +elig_api_routes.add_routes() +elig_api_exceptions = FlaskExceptions(app) +elig_api_exceptions.add_exceptions() @app.route("/", methods=["GET"]) def getMap():