76 lines
2.9 KiB
Python
76 lines
2.9 KiB
Python
import http.client as http_client
|
|
import json
|
|
import traceback
|
|
|
|
from ipe_fetcher.model import AreaCoordinates, Building, FAIEligibilityStatus
|
|
|
|
|
|
class Liazo:
|
|
def get_area_buildings(
|
|
self, narrow_coordinates: AreaCoordinates, existing_buildings: dict
|
|
) -> dict:
|
|
nc = narrow_coordinates
|
|
c = http_client.HTTPSConnection("vador.fdn.fr")
|
|
api_params = "etape=gps_batiments&lat1=%f&lat2=%f&lon1=%f&lon2=%f" % (
|
|
nc["swy"],
|
|
nc["ney"],
|
|
nc["swx"],
|
|
nc["nex"],
|
|
)
|
|
req = f"/souscription/gps-batiments.cgi?{api_params}"
|
|
req = req.replace(" ", "%20")
|
|
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
|
|
if r.status < 200 or r.status >= 300:
|
|
print("Erreur de serveur chez FDN.")
|
|
return existing_buildings
|
|
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:
|
|
fdn_elig_status = FAIEligibilityStatus(
|
|
isEligible=True,
|
|
ftthStatus="DEPLOYE", # Pas de status donc on dit que c'est ok mais on check avec l'arcep si axione KO cote front
|
|
reasonNotEligible=None,
|
|
)
|
|
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")
|
|
else:
|
|
buildings[id_imm]["found_in"] = ["liazo"]
|
|
if not buildings.get(id_imm):
|
|
building = Building(
|
|
y=building.get("lat"),
|
|
x=building.get("lon"),
|
|
idImm=id_imm,
|
|
numVoieImm="",
|
|
typeVoieImm="",
|
|
nomVoieImm="",
|
|
codePostal="",
|
|
commune="",
|
|
bat_info="",
|
|
found_in=["liazo"],
|
|
etat_imm_priority=4,
|
|
fdnEligStatus=fdn_elig_status,
|
|
aquilenetEligStatus=FAIEligibilityStatus(
|
|
isEligible=False, reasonNotEligible="", ftthStatus=""
|
|
),
|
|
othersEligStatus=FAIEligibilityStatus(
|
|
isEligible=False, reasonNotEligible="", ftthStatus=""
|
|
),
|
|
)
|
|
|
|
buildings[id_imm] = building
|
|
return buildings
|