Compare commits
12 Commits
905b3dcef8
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| b187a50878 | |||
| 826ff901cf | |||
| 66078799ff | |||
| 152bc9fd83 | |||
| 1a7828a850 | |||
| 7a195da164 | |||
| 29a0404643 | |||
| 57714ddd21 | |||
| 8cc72f50ee | |||
| fb3d7190b7 | |||
| 57f7f9252f | |||
| a7e630cd84 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,4 +3,5 @@
|
|||||||
__pycache__
|
__pycache__
|
||||||
venv
|
venv
|
||||||
__pycache__/
|
__pycache__/
|
||||||
pictures/
|
pictures/
|
||||||
|
*/__pycache__/
|
||||||
|
|||||||
108
huaweitest.py
108
huaweitest.py
@@ -1,37 +1,43 @@
|
|||||||
from fastapi import FastAPI, Query, Request
|
from fastapi import FastAPI, Query, Request, HTTPException
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import random
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def root():
|
async def root(request: Request):
|
||||||
|
# 获取当前时间
|
||||||
|
now = datetime.now()
|
||||||
|
|
||||||
|
# 格式化时间为 年-月-日 时:分:秒 的格式
|
||||||
|
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
print(f"请求IP地址: {request.client.host},请求时间{formatted_now},请求路径: /")
|
||||||
return "welcome to fastAPI!"
|
return "welcome to fastAPI!"
|
||||||
|
|
||||||
|
|
||||||
|
def random_bool():
|
||||||
|
return "true" if random.random() > 0.5 else "false"
|
||||||
|
|
||||||
|
|
||||||
@app.get("/script/getscriparam")
|
@app.get("/script/getscriparam")
|
||||||
async def getscriparam():
|
async def getscriparam(request: Request):
|
||||||
|
# 获取当前时间
|
||||||
|
now = datetime.now()
|
||||||
|
# 格式化时间为 年-月-日 时:分:秒 的格式
|
||||||
|
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
print(f"请求IP地址: {request.client.host},请求时间{formatted_now},请求路径: /script/getscriparam")
|
||||||
|
language_list = ["English (United States)", "Spanish (Mexico)", "English (United Kingdom)", "English (Australia)"]
|
||||||
data = {
|
data = {
|
||||||
"interaction": {
|
"interaction": {"from": 20, "to": 30},
|
||||||
"from": 20,
|
"bounceRate": {"from": 0.3, "to": 0.4},
|
||||||
"to": 30
|
"pagesToViewPerSession": {"from": 2, "to": 3},
|
||||||
},
|
"sessionsPerUser": {"from": 2, "to": 3},
|
||||||
"bounceRate": {
|
"ctr": {"from": 0.03, "to": 0.05},
|
||||||
"from": 0.3,
|
"shouldDoClick": "true",
|
||||||
"to": 0.4
|
"shouldExecute": "true",
|
||||||
},
|
"shouldBounce": "false",
|
||||||
"ctr": {
|
"languageFullName": random.choice(language_list),
|
||||||
"from": 0.03,
|
|
||||||
"to": 0.05
|
|
||||||
},
|
|
||||||
"pagesToViewPerSession": {
|
|
||||||
"from": 2,
|
|
||||||
"to": 3
|
|
||||||
},
|
|
||||||
"sessionsPerUser": {
|
|
||||||
"from": 2,
|
|
||||||
"to": 3
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return data
|
return data
|
||||||
@@ -46,7 +52,8 @@ async def do_success(request: Request):
|
|||||||
client_host = request.client.host
|
client_host = request.client.host
|
||||||
|
|
||||||
# 打印上报成功的时间和IP地址
|
# 打印上报成功的时间和IP地址
|
||||||
print(f"上报成功时间: {current_time}, IP地址: {client_host}")
|
# print(f"请求IP地址: {client_host},上报成功时间: {current_time}")
|
||||||
|
print(f"请求IP地址: {client_host},请求时间{current_time},请求路径: /script/success")
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
return {
|
return {
|
||||||
@@ -57,14 +64,15 @@ async def do_success(request: Request):
|
|||||||
|
|
||||||
|
|
||||||
@app.get("/script/failed")
|
@app.get("/script/failed")
|
||||||
async def do_failed(reason: str = None):
|
async def do_failed(request: Request, reason: str = None, errortype: str = None):
|
||||||
# 获取当前时间
|
# 获取当前时间
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
|
|
||||||
# 格式化时间为 年-月-日 时:分:秒 的格式
|
# 格式化时间为 年-月-日 时:分:秒 的格式
|
||||||
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
print(f"请求IP地址: {request.client.host},请求时间{formatted_now},请求路径: /script/failed")
|
||||||
# 假设这里记录失败原因到日志或数据库
|
# 假设这里记录失败原因到日志或数据库
|
||||||
print(f"上报失败,Time: {formatted_now}, 失败原因: {reason}") # 实际应用中应使用更专业的日志记录方式
|
print(f"上报失败,Time: {formatted_now}, 失败原因: {reason},失败类型: {errortype}.") # 实际应用中应使用更专业的日志记录方式
|
||||||
return {
|
return {
|
||||||
"code": 0,
|
"code": 0,
|
||||||
"msg": "ok",
|
"msg": "ok",
|
||||||
@@ -87,3 +95,51 @@ async def report_chrome_crash(id: str, timestamp: str = Query(None)):
|
|||||||
"msg": "ok",
|
"msg": "ok",
|
||||||
"data": {}
|
"data": {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/script/uploaddata")
|
||||||
|
async def upload_ads_status(impressions: str, clicks: str):
|
||||||
|
# 获取当前时间
|
||||||
|
now = datetime.now()
|
||||||
|
|
||||||
|
# 格式化时间为 年-月-日 时:分:秒 的格式
|
||||||
|
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
# 假设这里记录失败原因到日志或数据库
|
||||||
|
print(f"Time: {formatted_now}, impressions: {impressions}, clicks: {clicks}") # 实际应用中应使用更专业的日志记录方式
|
||||||
|
return {
|
||||||
|
"code": 0,
|
||||||
|
"msg": "ok",
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/api/account/")
|
||||||
|
async def get_account(request: Request):
|
||||||
|
server_token = "cT&Ur7AciCgL6P$2u!^mauI05r6jcD$A"
|
||||||
|
accounts = [
|
||||||
|
{"account": "reedavice8@gmail.com", "password": "L906lTeTlpelaq",
|
||||||
|
"auxiliary_mailbox": "tcmuffin56@mailexpire.com"},
|
||||||
|
{"account": "annist95g@gmail.com", "password": "28CUxUmygURereJ",
|
||||||
|
"auxiliary_mailbox": "b1youngster983@yahoo.ie"},
|
||||||
|
{"account": "vr8607864@gmail.com", "password": "J945YgaX", "auxiliary_mailbox": "sbqunmetal3@xtra.co.nz"},
|
||||||
|
{"account": "ShimoGuagliardo537@gmail.com", "password": "94Ss9YYx3",
|
||||||
|
"auxiliary_mailbox": "spigelmyerhalalikyzd185@yawua.us"},
|
||||||
|
]
|
||||||
|
|
||||||
|
# 从请求头中获取token
|
||||||
|
token = request.headers.get('Authorization')
|
||||||
|
# 获取当前时间
|
||||||
|
now = datetime.now()
|
||||||
|
# 格式化时间
|
||||||
|
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
print(f"请求IP地址: {request.client.host}, 请求时间: {formatted_now}, 请求token: {token}, 请求路径: /api/account/")
|
||||||
|
|
||||||
|
# 检查token是否存在且匹配
|
||||||
|
if not token or token != server_token:
|
||||||
|
# 如果token不正确,返回401未授权状态
|
||||||
|
raise HTTPException(status_code=401, detail="Unauthorized")
|
||||||
|
|
||||||
|
# 随机选择一个账户信息返回
|
||||||
|
selected_account = random.choice(accounts)
|
||||||
|
return selected_account
|
||||||
|
|||||||
@@ -14,6 +14,5 @@ sniffio==1.3.0
|
|||||||
starlette==0.32.0.post1
|
starlette==0.32.0.post1
|
||||||
typing_extensions==4.9.0
|
typing_extensions==4.9.0
|
||||||
uvicorn==0.25.0
|
uvicorn==0.25.0
|
||||||
uvloop==0.19.0
|
|
||||||
watchfiles==0.21.0
|
watchfiles==0.21.0
|
||||||
websockets==12.0
|
websockets==12.0
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
# Test your FastAPI endpoints
|
|
||||||
|
|
||||||
GET http://127.0.0.1:8000/
|
|
||||||
Accept: application/json
|
|
||||||
|
|
||||||
###
|
|
||||||
|
|
||||||
GET http://127.0.0.1:8000/hello/User
|
|
||||||
Accept: application/json
|
|
||||||
|
|
||||||
###
|
|
||||||
Binary file not shown.
15
website.py
15
website.py
@@ -1,14 +1,16 @@
|
|||||||
from fastapi import FastAPI, HTTPException, Request
|
import os
|
||||||
|
|
||||||
|
from fastapi import FastAPI, Request
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
||||||
from utils.pictures_handle import get_pictures_info
|
from utils.pictures_handle import get_pictures_info
|
||||||
from utils.pictures_handle import get_total_pages
|
from utils.pictures_handle import get_total_pages
|
||||||
import os
|
|
||||||
from fastapi.staticfiles import StaticFiles
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
app.mount("/static", StaticFiles(directory="pictures"), name="static")
|
app.mount("/static", StaticFiles(directory="assets/images/pictures/"), name="static")
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=["http://localhost:5173"], # 允许的源列表
|
allow_origins=["http://localhost:5173"], # 允许的源列表
|
||||||
@@ -40,7 +42,7 @@ async def get_menu():
|
|||||||
|
|
||||||
@app.get("/api/get-photo-list")
|
@app.get("/api/get-photo-list")
|
||||||
async def get_photo_list(page: int = 1, page_size: int = 10):
|
async def get_photo_list(page: int = 1, page_size: int = 10):
|
||||||
dir_path = "pictures"
|
dir_path = "assets/images/pictures"
|
||||||
total_pages = get_total_pages(dir_path, page_size)
|
total_pages = get_total_pages(dir_path, page_size)
|
||||||
photo_list = get_pictures_info(dir_path, page, page_size)
|
photo_list = get_pictures_info(dir_path, page, page_size)
|
||||||
for photo in photo_list:
|
for photo in photo_list:
|
||||||
@@ -56,8 +58,9 @@ async def get_photo_list(page: int = 1, page_size: int = 10):
|
|||||||
@app.get("/static/{photo_name}")
|
@app.get("/static/{photo_name}")
|
||||||
async def get_photo(photo_name: str,request: Request):
|
async def get_photo(photo_name: str,request: Request):
|
||||||
request_path = str(request.url)
|
request_path = str(request.url)
|
||||||
dir = "pictures"
|
dir = "/assets/images/pictures"
|
||||||
file_path = os.path.join(dir, photo_name)
|
file_path = os.path.join(dir, photo_name)
|
||||||
|
print(file_path)
|
||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
return FileResponse(file_path)
|
return FileResponse(file_path)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user