2022-03-23 22:54:04 +01:00
|
|
|
import http.client as httplib
|
|
|
|
from ipe_fetcher.model import AreaCoordinates, Building, FAIEligibilityStatus
|
|
|
|
import json
|
2023-01-11 15:35:12 +01:00
|
|
|
import time
|
|
|
|
import traceback
|
2022-03-23 22:54:04 +01:00
|
|
|
|
|
|
|
class Liazo:
|
|
|
|
def __init__(self):
|
2023-01-11 15:35:12 +01:00
|
|
|
pass
|
2022-03-23 22:54:04 +01:00
|
|
|
|
|
|
|
def getAreaBuildings(
|
2022-04-12 23:17:40 +02:00
|
|
|
self, narrow_coordinates: AreaCoordinates(), existing_buildings: dict
|
2022-03-23 22:54:04 +01:00
|
|
|
) -> dict:
|
2022-04-12 23:17:40 +02:00
|
|
|
nc=narrow_coordinates
|
2023-01-11 15:35:12 +01:00
|
|
|
c = httplib.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}"
|
2022-03-23 22:54:04 +01:00
|
|
|
req = req.replace(" ", "%20")
|
2023-01-11 15:35:12 +01:00
|
|
|
r = None
|
|
|
|
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.")
|
2022-11-30 19:29:27 +01:00
|
|
|
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:
|
2022-04-12 20:39:33 +02:00
|
|
|
fdnEligStatus = FAIEligibilityStatus(
|
|
|
|
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,
|
|
|
|
)
|
2022-03-23 22:54:04 +01:00
|
|
|
idImm=building.get('ref')
|
2022-04-12 20:39:33 +02:00
|
|
|
if buildings.get(idImm):
|
|
|
|
buildings[idImm]["fdnEligStatus"] = fdnEligStatus
|
|
|
|
if buildings[idImm].get('found_in'):
|
|
|
|
buildings[idImm]['found_in'].append("liazo")
|
|
|
|
else:
|
|
|
|
buildings[idImm]['found_in'] = ["liazo"]
|
2022-03-23 22:54:04 +01:00
|
|
|
if not buildings.get(idImm):
|
|
|
|
building = Building(
|
|
|
|
y=building.get('lat'),
|
|
|
|
x=building.get('lon'),
|
|
|
|
idImm=idImm,
|
|
|
|
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="",
|
|
|
|
found_in = ["liazo"],
|
2023-01-11 15:35:12 +01:00
|
|
|
etat_imm_priority=4,
|
2022-04-12 20:39:33 +02:00
|
|
|
fdnEligStatus=fdnEligStatus,
|
2022-04-12 23:17:40 +02:00
|
|
|
aquilenetEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""),
|
|
|
|
othersEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""),
|
2022-03-23 22:54:04 +01:00
|
|
|
)
|
2022-06-21 14:28:00 +02:00
|
|
|
|
2022-03-23 22:54:04 +01:00
|
|
|
buildings[idImm] = building
|
|
|
|
return buildings
|