diff --git a/.gitignore b/.gitignore index 0711160..e65487f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ .LSOverride # Icon must end with two \r -Icon +Icon # Thumbnails ._* diff --git a/.vscode/settings.json b/.vscode/settings.json index 1130a3e..effc8f0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,3 @@ { - "python.pythonPath": "/Users/gaugendre/.pyenv/versions/3.10.0/envs/tcl-filtrage/bin/python" -} \ No newline at end of file + "python.pythonPath": "/Users/gaugendre/.pyenv/versions/3.10.0/envs/tcl-filtrage/bin/python" +} diff --git a/main.py b/main.py index 0554b3e..486a26c 100644 --- a/main.py +++ b/main.py @@ -1,15 +1,19 @@ +import enum from typing import List, Optional + +import httpx from fastapi import FastAPI, HTTPException from fastapi.params import Header from pydantic import BaseModel -import enum, httpx app = FastAPI() + class PassageType(enum.Enum): E = "E" T = "T" + class Passage(BaseModel): coursetheorique: str delaipassage: str @@ -22,25 +26,31 @@ class Passage(BaseModel): ligne: str type: PassageType + class Passages(BaseModel): passages: List[Passage] + # Stop id can be optained using # https://data.grandlyon.com/jeux-de-donnees/points-arret-reseau-transports-commun-lyonnais/donnees @app.get("/stop/{stop_id}", response_model=Passages) async def stop(stop_id: int, authorization: Optional[str] = Header(None)): if authorization is None: raise HTTPException(status_code=401, detail="Not authenticated") - - headers = {'Authorization': authorization} + + headers = {"Authorization": authorization} async with httpx.AsyncClient(headers=headers) as client: - res = await client.get('https://download.data.grandlyon.com/ws/rdata/tcl_sytral.tclpassagearret/all.json?maxfeatures=-1') + res = await client.get( + "https://download.data.grandlyon.com/ws/rdata/tcl_sytral.tclpassagearret/all.json?maxfeatures=-1" + ) if res.status_code != 200: - raise HTTPException(status_code=res.status_code, detail="HTTP error during call to remote API") - + raise HTTPException( + status_code=res.status_code, + detail="HTTP error during call to remote API", + ) + passages: List[Passage] = [] for passage in res.json().get("values"): if passage.get("id") == stop_id: passages.append(passage) return Passages(passages=passages) - \ No newline at end of file