Files
auto_control/config.py
T
butubb 02016b7b85 feat: 悬空设备自愈 - 启动可选自动释放残留 STF 占用
崩溃/强杀后设备残留占用需手动清理。新增 AUTO_RELEASE_STALE_OCCUPY 配置
(默认关):单实例部署设为 true 时,web_server 启动自动释放本账户残留占用;
多实例共用 STF 账户时勿开(会误放另一实例任务)。默认仅启动提示。
2026-08-08 21:31:53 +08:00

67 lines
2.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""项目根配置:只放核心程序级配置。
任务自身的参数(观看时长、点赞开关、滑动速度等)不在这里,
放各自 tasks/xxx.py 顶部,保持每个任务自包含、互不干扰。
改 STF 地址/token、adb 路径、web 端口都改这里。
安全:STF_TOKEN / WEB_SECRET_KEY 建议用环境变量注入(生产不要提交到 git)。
支持 `.env` 文件(项目根目录),也可直接 `export STF_TOKEN=xxx`。
"""
import os
# 可选加载 .env 文件(不存在则忽略)
_env_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), ".env")
if os.path.exists(_env_path):
try:
with open(_env_path, encoding="utf-8") as _f:
for _line in _f:
_line = _line.strip()
if _line and not _line.startswith("#") and "=" in _line:
_k, _v = _line.split("=", 1)
os.environ.setdefault(_k.strip(), _v.strip())
except OSError:
pass
def _env(key, default):
"""读环境变量,未设置则返回默认值。"""
return os.environ.get(key, default)
# ================== STF 配置 ==================
STF_URL = _env("STF_URL", "http://192.168.20.220:7100")
STF_TOKEN = _env("STF_TOKEN", "9024544b571647d3a6b09dab5dbfcb28bfd950f5b659400394e44e7217b7051b")
# ================== adb 路径 ==================
# adb 二进制及依赖统一放在 bin/adb/ 下
# Windows: adb.exe(依赖同目录的 dll)
# Linux: adb(需 chmod +x,Linux 版二进制)
# 代码自动识别操作系统,用户只需把对应平台的 adb 放进 bin/adb/
import sys as _sys
_ADB_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "bin", "adb")
if _sys.platform == "win32":
ADB_PATH = os.path.join(_ADB_DIR, "adb.exe")
else:
# Linux / macOS:用 bin/adb/adb(无 .exe 后缀)
# 部署后需执行 chmod +x bin/adb/adb
ADB_PATH = os.path.join(_ADB_DIR, "adb")
# ================== Web 后台 ==================
WEB_HOST = "0.0.0.0"
# 端口必须避开 Windows 动态端口范围(本机被改成 1024-15000,默认 49152-65535)
# 用 18050 处于动态范围之外,不会被出站连接随机占用,避免 WinError 10013
WEB_PORT = 18050
# ================== 数据目录 ==================
# 持久化数据(分组、任务计划)存放目录
DATA_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data")
# APK 文件存储目录(应用管理功能)
APK_DIR = os.path.join(DATA_DIR, "apks")
# ================== 悬空设备自愈 ==================
# 启动时是否自动释放"仍被本账户占用"的设备(上次崩溃/强杀残留)。
# 仅单实例部署时设为 True:多实例共用同一 STF 账户时不要开,会误释放另一实例的运行中任务。
AUTO_RELEASE_STALE_OCCUPY = _env("AUTO_RELEASE_STALE_OCCUPY", "false").lower() in ("1", "true", "yes")