chore: Clean up and refactor codebase for improved maintainability

- Removed obsolete command-line test parameters from `run_cli.py` to streamline functionality.
- Introduced a new `ocr_preprocess.py` module for unified OCR image preprocessing, enhancing recognition stability.
- Updated various components to utilize the new preprocessing function, improving code organization and readability.
- Adjusted configuration values in `config.json` for better performance and consistency.
- Added comprehensive technical documentation for the Douyin project, detailing code modification standards and operational guidelines.
- Cleaned up excessive blank lines across multiple files to enhance overall readability.
This commit is contained in:
Your Name committed 2025-12-30 23:11:34 +08:00
1 parent efe6e2252f
commit 223c127e11
70 files changed
+17121 -1752

No files matched your search

+16 -37
View File
@@ -825,12 +825,13 @@ class ProcRunner:
def get_reservations(self) -> dict:
"""获取当前预约队列信息(来自子进程写入的 douyin/core/state/reservations.json)。"""
try:
import path_config
path = path_config.get_reservations_path()
except Exception:
# 回退到旧路径(向后兼容)
path = path_config.get_reservations_path()
if hasattr(path_config, "get_reservations_path"):
try:
path = path_config.get_reservations_path()
except Exception:
path = os.path.join(path_config.PROJECT_ROOT if hasattr(path_config, "PROJECT_ROOT") else os.getcwd(), "douyin", "state", "reservations.json")
else:
path = os.path.join(os.getcwd(), "douyin", "state", "reservations.json")
try:
if os.path.exists(path):
with open(path, "r", encoding="utf-8") as f:
@@ -1577,13 +1578,14 @@ class Handler(BaseHTTPRequestHandler):
n = int((qs.get("lines") or [200])[0])
except Exception:
n = 200
# 使用统一的路径配置
try:
import path_config
path = path_config.get_actions_log_path()
except Exception:
# 回退到旧路径(向后兼容)
path = path_config.get_actions_log_path()
# 使用统一的路径配置(优先使用 path_config 中的配置,失败时回退到项目内置路径)
if hasattr(path_config, "get_actions_log_path"):
try:
path = path_config.get_actions_log_path()
except Exception:
path = os.path.join(path_config.PROJECT_ROOT if hasattr(path_config, "PROJECT_ROOT") else os.getcwd(), "logs", "actions.log")
else:
path = os.path.join(os.getcwd(), "logs", "actions.log")
out_lines: list[str] = []
try:
if os.path.exists(path):
@@ -1779,29 +1781,7 @@ class Handler(BaseHTTPRequestHandler):
return self._send_json({"ok": False, "error": str(e)}, status=500)
return self._send_json({"ok": True})
if u.path == "/api/test-yanghao":
if RUNNER.is_running():
return self._send_json({"ok": False, "error": "running"}, status=409)
body = self._read_json()
device_id = str(body.get("device_id") or "").strip()
seconds = int(body.get("seconds") or 60)
try:
RUNNER.start_test_yanghao(device_id, seconds)
except Exception as e:
return self._send_json({"ok": False, "error": str(e)}, status=500)
return self._send_json({"ok": True})
if u.path == "/api/test-comment":
if RUNNER.is_running():
return self._send_json({"ok": False, "error": "running"}, status=409)
body = self._read_json()
device_id = str(body.get("device_id") or "").strip()
text = str(body.get("text") or "").strip()
try:
RUNNER.start_test_comment(device_id, text)
except Exception as e:
return self._send_json({"ok": False, "error": str(e)}, status=500)
return self._send_json({"ok": True})
# (已移除) /api/test-yanghao 与 /api/test-comment 接口已删除
if u.path == "/api/stop":
RUNNER.stop()
@@ -1854,7 +1834,6 @@ def main() -> int:
raise
print(f"Web GUI: http://{host}:{port}")
print("- 可在页面里设置养号时长/间隔并保存到 config.json")
print("- 可一键运行‘测试养号流程’,日志会在页面里滚动显示")
try:
httpd.serve_forever()
except KeyboardInterrupt: