57 lines
1.3 KiB
Python
57 lines
1.3 KiB
Python
from OSMPythonTools.api import Api
|
|
from OSMPythonTools.overpass import Overpass
|
|
from dataclasses import dataclass
|
|
|
|
|
|
# Defines the landmark class (aka some place there is to visit)
|
|
@dataclass
|
|
class Landmarkkkk :
|
|
name : str
|
|
attractiveness : int
|
|
id : int
|
|
|
|
@dataclass
|
|
class Landmark :
|
|
name : str
|
|
attractiveness : int
|
|
loc : tuple
|
|
|
|
# Converts a OSM id to a landmark
|
|
def add_from_id(id: int, score: int) :
|
|
|
|
try :
|
|
s = 'way/' + str(id) # prepare string for query
|
|
obj = api.query(s) # object to add
|
|
except :
|
|
s = 'relation/' + str(id) # prepare string for query
|
|
obj = api.query(s) # object to add
|
|
|
|
return Landmarkkkk(obj.tag('name:fr'), score, id) # create Landmark out of it
|
|
|
|
|
|
# take a lsit of tuples (id, score) to generate a list of landmarks
|
|
def generate_landmarks(ids_and_scores: list) :
|
|
|
|
L = []
|
|
for tup in ids_and_scores :
|
|
L.append(add_from_id(tup[0], tup[1]))
|
|
|
|
return L
|
|
|
|
api = Api()
|
|
|
|
|
|
l = (7515426, 70)
|
|
t = (5013364, 100)
|
|
n = (201611261, 99)
|
|
a = (226413508, 50)
|
|
m = (23762981, 30)
|
|
|
|
|
|
ids_and_scores = [t, l, n, a, m]
|
|
|
|
landmarks = generate_landmarks(ids_and_scores)
|
|
|
|
|
|
for obj in landmarks :
|
|
print(obj) |