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

59 lines
2.4 KiB
Python

import http.client as httplib
from ipe_fetcher.model import AreaCoordinates, Building, FAIEligibilityStatus
import json
class Liazo:
def __init__(self):
self.https_conn = httplib.HTTPSConnection("vador.fdn.fr")
def getAreaBuildings(
self, narrow_coordinates: AreaCoordinates(), existing_buildings: dict
) -> dict:
nc=narrow_coordinates
c = self.https_conn
req = "/souscription/gps-batiments.cgi?etape=gps_batiments&lat1=%f&lat2=%f&lon1=%f&lon2=%f" % (nc['swy'],nc['ney'],nc['swx'],nc['nex'])
req = req.replace(" ", "%20")
c.request("GET", req)
r = c.getresponse()
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:
fdnEligStatus = 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,
)
idImm=building.get('ref')
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"]
if not buildings.get(idImm):
building = Building(
y=building.get('lat'),
x=building.get('lon'),
idImm=idImm,
numVoieImm="",
typeVoieImm="",
nomVoieImm="",
codePostal="",
commune="",
bat_info="",
found_in = ["liazo"],
etat_imm_priority=1,
fdnEligStatus=fdnEligStatus,
aquilenetEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""),
othersEligStatus=FAIEligibilityStatus(isEligible=False, reasonNotEligible="", ftthStatus=""),
)
buildings[idImm] = building
return buildings