Spaces:
Sleeping
Sleeping
Download app.py from Inayatgaming/WhereIsMyTrainAPI: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/spaces/Inayatgaming/WhereIsMyTrainAPI/resolve/main/app.py
- Command line
-
hf download hf://spaces/Inayatgaming/WhereIsMyTrainAPI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Inayatgaming/WhereIsMyTrainAPI/resolve/main/app.py
1.46 kB
| from fastapi import FastAPI, Query, HTTPException | |
| from MultiFeatures.IndianRailway import whereismytrain | |
| app = FastAPI( | |
| title="Where Is My Train API", | |
| version="1.0.0" | |
| ) | |
| wit = whereismytrain.WhereIsMyTrain() | |
| async def root(): | |
| return { | |
| "status": "online", | |
| "service": "Where Is My Train wrapper", | |
| "endpoints": [ | |
| "/live", | |
| "/station" | |
| ] | |
| } | |
| async def live( | |
| train: str = Query(...), | |
| date: str = Query(...), | |
| from_station: str = Query(..., alias="from"), | |
| to_station: str = Query(..., alias="to"), | |
| from_day: int = Query(1), | |
| lang: str = Query("en") | |
| ): | |
| try: | |
| result = await wit.live_status( | |
| train_no=train, | |
| date=date, | |
| from_station=from_station, | |
| to_station=to_station, | |
| from_day=from_day, | |
| lang=lang | |
| ) | |
| return result | |
| except Exception as e: | |
| raise HTTPException( | |
| status_code=502, | |
| detail=str(e) | |
| ) | |
| async def station( | |
| code: str = Query(...), | |
| hours: int = Query(8), | |
| lang: str = Query("en") | |
| ): | |
| try: | |
| result = await wit.live_station( | |
| station_code=code, | |
| hrs=hours, | |
| lang=lang | |
| ) | |
| return result | |
| except Exception as e: | |
| raise HTTPException( | |
| status_code=502, | |
| detail=str(e) | |
| ) |