Axione-IPE-Viewer/webapp/ipe_fetcher/liazo.py

77 lines
2.9 KiB
Python
Raw Permalink Normal View History

2023-02-28 22:31:35 +01:00
import http.client as http_client
2022-03-23 22:54:04 +01:00
import json
2023-01-11 15:35:12 +01:00
import traceback
2022-03-23 22:54:04 +01:00
2023-02-28 22:31:35 +01:00
from ipe_fetcher.model import AreaCoordinates, Building, FAIEligibilityStatus
2023-01-11 16:57:07 +01:00
2022-03-23 22:54:04 +01:00
class Liazo:
2023-02-28 22:31:35 +01:00
def get_area_buildings(
self, narrow_coordinates: AreaCoordinates, existing_buildings: dict
2022-03-23 22:54:04 +01:00
) -> dict:
2023-01-11 16:57:07 +01:00
nc = narrow_coordinates
2023-02-28 22:31:35 +01:00
c = http_client.HTTPSConnection("vador.fdn.fr")
2023-01-11 16:57:07 +01:00
api_params = "etape=gps_batiments&lat1=%f&lat2=%f&lon1=%f&lon2=%f" % (
nc["swy"],
nc["ney"],
nc["swx"],
nc["nex"],
)
2023-01-11 15:35:12 +01:00
req = f"/souscription/gps-batiments.cgi?{api_params}"
2022-03-23 22:54:04 +01:00
req = req.replace(" ", "%20")
2023-01-11 15:35:12 +01:00
try:
c.request("GET", req)
r = c.getresponse()
except Exception:
print(f"Could not call Liazo API to get Buildings, params: {api_params}")
print(traceback.format_exc())
return existing_buildings
2022-03-23 22:54:04 +01:00
if r.status < 200 or r.status >= 300:
2022-04-12 23:17:40 +02:00
print("Erreur de serveur chez FDN.")
return existing_buildings
2022-03-23 22:54:04 +01:00
d = r.read()
c.close()
v = json.loads(d.decode("utf-8"))
if not existing_buildings:
existing_buildings = dict()
buildings = existing_buildings
for building in v:
2023-02-28 22:31:35 +01:00
fdn_elig_status = FAIEligibilityStatus(
2022-04-12 20:39:33 +02:00
isEligible=True,
2023-01-11 15:35:12 +01:00
ftthStatus="DEPLOYE", # Pas de status donc on dit que c'est ok mais on check avec l'arcep si axione KO cote front
2022-04-12 20:39:33 +02:00
reasonNotEligible=None,
)
2023-02-28 22:31:35 +01:00
id_imm = building.get("ref")
if buildings.get(id_imm):
buildings[id_imm]["fdnEligStatus"] = fdn_elig_status
if buildings[id_imm]["etat_imm_priority"] > 4:
buildings[id_imm]["etat_imm_priority"] = 4
if buildings[id_imm].get("found_in"):
buildings[id_imm]["found_in"].append("liazo")
2022-04-12 20:39:33 +02:00
else:
2023-02-28 22:31:35 +01:00
buildings[id_imm]["found_in"] = ["liazo"]
if not buildings.get(id_imm):
2022-03-23 22:54:04 +01:00
building = Building(
2023-01-11 16:57:07 +01:00
y=building.get("lat"),
x=building.get("lon"),
2023-02-28 22:31:35 +01:00
idImm=id_imm,
2022-03-23 22:54:04 +01:00
numVoieImm="",
typeVoieImm="",
2022-04-12 20:39:33 +02:00
nomVoieImm="",
2022-04-12 23:17:40 +02:00
codePostal="",
commune="",
2022-04-12 20:39:33 +02:00
bat_info="",
2023-01-11 16:57:07 +01:00
found_in=["liazo"],
2023-01-11 15:35:12 +01:00
etat_imm_priority=4,
2023-02-28 22:31:35 +01:00
fdnEligStatus=fdn_elig_status,
2023-01-11 16:57:07 +01:00
aquilenetEligStatus=FAIEligibilityStatus(
isEligible=False, reasonNotEligible="", ftthStatus=""
),
othersEligStatus=FAIEligibilityStatus(
isEligible=False, reasonNotEligible="", ftthStatus=""
),
2022-03-23 22:54:04 +01:00
)
2023-02-28 22:31:35 +01:00
buildings[id_imm] = building
2022-03-23 22:54:04 +01:00
return buildings