fastApiProject/main.py
2024-05-06 13:09:50 +08:00

71 lines
1.8 KiB
Python

from fastapi import FastAPI
import requests
from flask import request
from requests_toolbelt import MultipartEncoder
import renamePhotoBatch
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
@app.get("/hello/{name}")
async def say_hello(name: str):
return {"message": f"Hello {name}"}
@app.post("/rename_photo")
async def rename_photo():
return renamePhotoBatch.solution(request.form.get('path'))
# 获取文章列表
def get_post_list_urls(page, username):
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0"
}
lb_params = {
"page": page,
"size": "20",
"businessType": "blog",
"orderby": "",
"noMore": "false",
"year": "",
"month": "",
"username": username,
}
urls = "https://blog.csdn.net/community/home-api/v1/get-business-list"
try:
res = requests.get(url=urls, headers=headers, params=lb_params)
# print(res.status_code)
data_list = res.json()["data"]["list"]
return data_list
except Exception as e:
print(f"[+] [ending] [{e}]")
return 0
# 查询质量分数
def get_sorce(article_url):
url = "https://bizapi.csdn.net/trends/api/v1/get-article-score"
headers = {
# headers
}
params = MultipartEncoder({"url": article_url})
headers["Content-Type"] = params.content_type
try:
res = requests.post(
url,
headers=headers,
data=params,
timeout=10,
)
# print(f"[+] [{article_url}] [{res.status_code}] ")
sorce = res.json()["data"]["score"]
# print(sorce)
return sorce
except Exception as e:
print(f"[+] [分数获取失败] [{article_url}] [{res.status_code}] [{e}]")
return 0