🎨 将文本内容同一更新
🐛 修复偷菜无法正常计算的BUG
This commit is contained in:
+21
-14
@@ -1,6 +1,5 @@
|
||||
import json
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
import httpx
|
||||
|
||||
@@ -15,12 +14,14 @@ class CRequestManager:
|
||||
m_sTokens = "xZ%?z5LtWV7H:0-Xnwp+bNRNQ-jbfrxG"
|
||||
|
||||
@classmethod
|
||||
async def download(cls,
|
||||
url: str,
|
||||
savePath: str,
|
||||
fileName: str,
|
||||
params: dict | None = None,
|
||||
jsonData: dict | None = None) -> bool:
|
||||
async def download(
|
||||
cls,
|
||||
url: str,
|
||||
savePath: str,
|
||||
fileName: str,
|
||||
params: dict | None = None,
|
||||
jsonData: dict | None = None,
|
||||
) -> bool:
|
||||
"""下载文件到指定路径并覆盖已存在的文件
|
||||
|
||||
Args:
|
||||
@@ -51,7 +52,9 @@ class CRequestManager:
|
||||
f.write(response.content)
|
||||
return True
|
||||
else:
|
||||
logger.warning(f"文件下载失败: HTTP {response.status_code} {response.text}")
|
||||
logger.warning(
|
||||
f"文件下载失败: HTTP {response.status_code} {response.text}"
|
||||
)
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
@@ -84,7 +87,9 @@ class CRequestManager:
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
else:
|
||||
logger.warning(f"{name}请求失败: HTTP {response.status_code} {response.text}")
|
||||
logger.warning(
|
||||
f"{name}请求失败: HTTP {response.status_code} {response.text}"
|
||||
)
|
||||
return {}
|
||||
except httpx.RequestError as e:
|
||||
logger.warning(f"{name}请求异常", e=e)
|
||||
@@ -115,7 +120,9 @@ class CRequestManager:
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
else:
|
||||
logger.warning(f"{name}请求失败: HTTP {response.status_code} {response.text}")
|
||||
logger.warning(
|
||||
f"{name}请求失败: HTTP {response.status_code} {response.text}"
|
||||
)
|
||||
return {}
|
||||
except httpx.RequestError as e:
|
||||
logger.warning(f"{name}请求异常", e=e)
|
||||
@@ -128,7 +135,7 @@ class CRequestManager:
|
||||
async def initSignInFile(cls) -> bool:
|
||||
if os.path.exists(g_sSignInPath):
|
||||
try:
|
||||
with open(g_sSignInPath, "r", encoding="utf-8") as f:
|
||||
with open(g_sSignInPath, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
sign = json.loads(content)
|
||||
|
||||
@@ -141,8 +148,8 @@ class CRequestManager:
|
||||
else:
|
||||
logger.warning("真寻农场签到文件检查失败, 即将下载")
|
||||
return await cls.downloadSignInFile()
|
||||
except json.JSONDecodeError as e:
|
||||
logger.warning(f"真寻农场签到文件格式错误, 即将下载")
|
||||
except json.JSONDecodeError:
|
||||
logger.warning("真寻农场签到文件格式错误, 即将下载")
|
||||
return await cls.downloadSignInFile()
|
||||
else:
|
||||
return await cls.downloadSignInFile()
|
||||
@@ -156,7 +163,7 @@ class CRequestManager:
|
||||
path = str(g_sSignInPath.parent.resolve(strict=False))
|
||||
yearMonth = g_pToolManager.dateTime().now().strftime("%Y%m")
|
||||
|
||||
await cls.download(url, path, "signTemp.json", jsonData={'date':yearMonth})
|
||||
await cls.download(url, path, "signTemp.json", jsonData={"date": yearMonth})
|
||||
g_pToolManager.renameFile(f"{path}/signTemp.json", "sign_in.json")
|
||||
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user