-
Notifications
You must be signed in to change notification settings - Fork 0
/
locate_buildings.py
41 lines (34 loc) · 1.09 KB
/
locate_buildings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from typing import List
from parse_buildings import Building, all_buildings
from dataclasses import dataclass, asdict
import pyphoton
from cache import cached
import logging
__LOGGER__ = logging.getLogger(__name__)
@dataclass
class LocatedBuilding(Building):
lat: float
lon: float
def locate_buildings(buildings: List[Building]):
phclient = pyphoton.Photon(host="https://photon.komoot.io")
located_buildings = []
for b in buildings:
__LOGGER__.info(f"Locating {b.name}")
location = phclient.query(
f"{b.street}, {b.city}",
limit=1
)
if location:
located_buildings.append(
LocatedBuilding(lat=location.latitude, lon=location.longitude, **asdict(b))
)
else:
__LOGGER__.warning(f"Did not find location of {b.name}")
return located_buildings
@cached("LOCATED_BUILDING_LIST")
def all_located_buildings():
return locate_buildings(all_buildings())
if __name__ == '__main__':
located_buildings = all_located_buildings()
for lb in located_buildings:
print(lb)