51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi import Request, Response
|
|
from fastapi.responses import JSONResponse, FileResponse
|
|
import json
|
|
import requests
|
|
|
|
app = FastAPI()
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return FileResponse("index.html")
|
|
|
|
@app.get("/api/station")
|
|
async def getApiStation():
|
|
with open("json/station.json", "r") as f:
|
|
return json.load(f)
|
|
|
|
@app.get("/api/rail/{type}")
|
|
async def getApiRail(type: str):
|
|
with open(f"json/rail_{type}.json", "r") as f:
|
|
return json.load(f)
|
|
|
|
|
|
@app.get("/api/train")
|
|
async def getApiTrain():
|
|
tapi = requests.get('https://gis.korail.com/api/train?bbox=120.6263671875,28.07910949377748,134.0736328125,45.094739803960664',
|
|
headers = {
|
|
"x-requested-with": "com.korail.talk",
|
|
"referer": "https://gis.korail.com/korailTalk/entrance",
|
|
"user-agent": "korailtalk AppVersion/6.3.3"
|
|
})
|
|
|
|
return tapi.json()
|
|
|
|
with open("json/trains.json", "r") as f:
|
|
return json.load(f)
|
|
|
|
|
|
if __name__=="__main__":
|
|
import uvicorn
|
|
uvicorn.run(app)
|