Files
jianli-boss/client/main.py
T
2026-08-25 19:03:41 +08:00

74 lines
1.9 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.
"""
客户端主入口
启动本地 Web 控制面板,并在浏览器中自动打开。
运行方式:python -m client.main
"""
import sys
import threading
import webbrowser
import uvicorn
from loguru import logger
from .config import client_settings
from .fingerprint import get_machine_summary
def setup_logger() -> None:
logger.remove()
logger.add(
sys.stderr,
level="INFO",
format="<green>{time:HH:mm:ss}</green> | <level>{level:<7}</level> | {message}",
colorize=True,
)
logger.add(
"client/logs/client.log",
level="DEBUG",
format="{time:YYYY-MM-DD HH:mm:ss} | {level:<7} | {message}",
encoding="utf-8",
rotation="10 MB",
retention="7 days",
enqueue=True,
)
def open_browser_later(url: str, delay: float = 1.5) -> None:
def _open():
import time
time.sleep(delay)
webbrowser.open(url)
threading.Thread(target=_open, daemon=True).start()
def main() -> None:
setup_logger()
machine = get_machine_summary()
logger.info(f"本机:{machine['hostname']} ({machine['system']})")
logger.info(f"机器指纹:{machine['client_code']}")
logger.info(f"云端服务端地址:{client_settings.SERVER_URL}")
if not client_settings.ADSPOWER_USER_ID:
logger.warning("尚未配置 AdsPower Profile ID(ADSPOWER_USER_ID),请在 client/.env 中填写")
if not client_settings.AI_API_KEY:
logger.warning("尚未配置 AI_API_KEY,AI 评分功能将不可用")
host = client_settings.WEB_HOST
port = client_settings.WEB_PORT
url = f"http://{host}:{port}"
logger.success(f"控制面板地址:{url}")
open_browser_later(url)
# 启动本地 Web 服务
uvicorn.run(
"client.web.app:app",
host=host,
port=port,
log_level="warning",
)
if __name__ == "__main__":
main()