Reformat
This commit is contained in:
parent
ce7eecfd3d
commit
8d0ca77be1
3 changed files with 20 additions and 10 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -8,7 +8,7 @@
|
|||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
|
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"python.pythonPath": "/Users/gaugendre/.pyenv/versions/3.10.0/envs/tcl-filtrage/bin/python"
|
||||
}
|
||||
"python.pythonPath": "/Users/gaugendre/.pyenv/versions/3.10.0/envs/tcl-filtrage/bin/python"
|
||||
}
|
||||
|
|
24
main.py
24
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)
|
||||
|
Reference in a new issue