Compare commits
4 Commits
fba2513b5f
...
905b3dcef8
| Author | SHA1 | Date |
|---|---|---|
|
|
905b3dcef8 | |
|
|
dab5c40e31 | |
|
|
e64a56e4d0 | |
|
|
c7788c409f |
|
|
@ -2,5 +2,5 @@
|
||||||
.DS_Store
|
.DS_Store
|
||||||
__pycache__
|
__pycache__
|
||||||
venv
|
venv
|
||||||
__pycache__/main.cpython-311.pyc
|
__pycache__/
|
||||||
pictures/
|
pictures/
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -1,4 +1,5 @@
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI, Query, Request
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
@ -10,18 +11,43 @@ async def root():
|
||||||
|
|
||||||
@app.get("/script/getscriparam")
|
@app.get("/script/getscriparam")
|
||||||
async def getscriparam():
|
async def getscriparam():
|
||||||
data = {"bounceRate": {"from": 0.3, "to": 0.4}, "ctr": {"from": 0.03, "to": 0.05},
|
data = {
|
||||||
"interaction": {"from": 20, "to": 30},
|
"interaction": {
|
||||||
"pagesToViewPerSession": {"from": 2, "to": 3}, "sessionsPerUser": {"from": 2, "to": 3}}
|
"from": 20,
|
||||||
return {
|
"to": 30
|
||||||
"code": 0,
|
},
|
||||||
"msg": "ok",
|
"bounceRate": {
|
||||||
"data": data
|
"from": 0.3,
|
||||||
|
"to": 0.4
|
||||||
|
},
|
||||||
|
"ctr": {
|
||||||
|
"from": 0.03,
|
||||||
|
"to": 0.05
|
||||||
|
},
|
||||||
|
"pagesToViewPerSession": {
|
||||||
|
"from": 2,
|
||||||
|
"to": 3
|
||||||
|
},
|
||||||
|
"sessionsPerUser": {
|
||||||
|
"from": 2,
|
||||||
|
"to": 3
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
@app.get("/script/success")
|
@app.get("/script/success")
|
||||||
async def do_success():
|
async def do_success(request: Request):
|
||||||
|
# 获取当前时间
|
||||||
|
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
# 获取请求者的IP地址
|
||||||
|
client_host = request.client.host
|
||||||
|
|
||||||
|
# 打印上报成功的时间和IP地址
|
||||||
|
print(f"上报成功时间: {current_time}, IP地址: {client_host}")
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
return {
|
return {
|
||||||
"code": 0,
|
"code": 0,
|
||||||
|
|
@ -32,8 +58,30 @@ async def do_success():
|
||||||
|
|
||||||
@app.get("/script/failed")
|
@app.get("/script/failed")
|
||||||
async def do_failed(reason: str = None):
|
async def do_failed(reason: str = None):
|
||||||
|
# 获取当前时间
|
||||||
|
now = datetime.now()
|
||||||
|
|
||||||
|
# 格式化时间为 年-月-日 时:分:秒 的格式
|
||||||
|
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
# 假设这里记录失败原因到日志或数据库
|
# 假设这里记录失败原因到日志或数据库
|
||||||
print(f"失败原因: {reason}") # 实际应用中应使用更专业的日志记录方式
|
print(f"上报失败,Time: {formatted_now}, 失败原因: {reason}") # 实际应用中应使用更专业的日志记录方式
|
||||||
|
return {
|
||||||
|
"code": 0,
|
||||||
|
"msg": "ok",
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/report/chrome/crash")
|
||||||
|
async def report_chrome_crash(id: str, timestamp: str = Query(None)):
|
||||||
|
# 获取当前时间
|
||||||
|
now = datetime.now()
|
||||||
|
|
||||||
|
# 格式化时间为 年-月-日 时:分:秒 的格式
|
||||||
|
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
# 假设这里记录失败原因到日志或数据库
|
||||||
|
print(f"Time: {formatted_now}, ID: {id}, 时间戳: {timestamp}") # 实际应用中应使用更专业的日志记录方式
|
||||||
return {
|
return {
|
||||||
"code": 0,
|
"code": 0,
|
||||||
"msg": "ok",
|
"msg": "ok",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue