42 lines
1.5 KiB
Python
42 lines
1.5 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, center_lat: float, center_lng: float, existing_buildings: dict
|
||
|
) -> dict:
|
||
|
c = self.https_conn
|
||
|
req = "/souscription/gps-batiments.cgi?etape=gps_batiments&lat1=%f&lat2=%f&lon1=%f&lon2=%f" % (center_lat-0.0011, center_lat+0.0011, center_lng-0.0022, center_lng+0.0022)
|
||
|
req = req.replace(" ", "%20")
|
||
|
print("Req FDN with: ", req)
|
||
|
c.request("GET", req)
|
||
|
r = c.getresponse()
|
||
|
if r.status < 200 or r.status >= 300:
|
||
|
print("Erreur de serveur chez FDN. Merci de nous faire remonter le numéro de téléphone qui provoque cette erreur")
|
||
|
return
|
||
|
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:
|
||
|
idImm=building.get('ref')
|
||
|
if not buildings.get(idImm):
|
||
|
|
||
|
building = Building(
|
||
|
y=building.get('lat'),
|
||
|
x=building.get('lon'),
|
||
|
idImm=idImm,
|
||
|
numVoieImm="",
|
||
|
typeVoieImm="",
|
||
|
nomVoieImm=""
|
||
|
)
|
||
|
print("add building ", building)
|
||
|
buildings[idImm] = building
|
||
|
return buildings
|