42 lines
940 B
Python
42 lines
940 B
Python
from fastapi import FastAPI
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return "welcome to fastAPI!"
|
|
|
|
|
|
@app.get("/script/getscriparam")
|
|
async def getscriparam():
|
|
data = {"bounceRate": {"from": 0.3, "to": 0.4}, "ctr": {"from": 0.03, "to": 0.05},
|
|
"interaction": {"from": 20, "to": 30},
|
|
"pagesToViewPerSession": {"from": 2, "to": 3}, "sessionsPerUser": {"from": 2, "to": 3}}
|
|
return {
|
|
"code": 0,
|
|
"msg": "ok",
|
|
"data": data
|
|
}
|
|
|
|
|
|
@app.get("/script/success")
|
|
async def do_success():
|
|
data = {}
|
|
return {
|
|
"code": 0,
|
|
"msg": "ok",
|
|
"data": data
|
|
}
|
|
|
|
|
|
@app.get("/script/failed")
|
|
async def do_failed(reason: str = None):
|
|
# 假设这里记录失败原因到日志或数据库
|
|
print(f"失败原因: {reason}") # 实际应用中应使用更专业的日志记录方式
|
|
return {
|
|
"code": 0,
|
|
"msg": "ok",
|
|
"data": {}
|
|
}
|