mirror of
https://github.com/morgan9e/KorailMap
synced 2026-04-15 00:44:13 +09:00
init
This commit is contained in:
50
main.py
Normal file
50
main.py
Normal file
@@ -0,0 +1,50 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user