proper fast api suage

This commit is contained in:
2024-05-29 18:14:40 +02:00
committed by Remy Moll
parent 175cf3e350
commit de221493ce
6 changed files with 1774 additions and 1006 deletions

View File

@@ -1,52 +1,57 @@
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 Landmark :
name : str
attractiveness : int
id : int
# 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 Landmark(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 :
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)

View File

@@ -1,23 +1,23 @@
import fastapi
from dataclasses import dataclass
@dataclass
class Destination:
name: str
location: tuple
attractiveness: int
d = Destination()
def get_route() -> list[Destination]:
return {"route": "Hello World"}
endpoint = ("/get_route", get_route)
end
if __name__ == "__main__":
fastapi.run()
import fastapi
from dataclasses import dataclass
@dataclass
class Destination:
name: str
location: tuple
attractiveness: int
d = Destination()
def get_route() -> list[Destination]:
return {"route": "Hello World"}
endpoint = ("/get_route", get_route)
end
if __name__ == "__main__":
fastapi.run()