89 lines
2.5 KiB
Python
89 lines
2.5 KiB
Python
|
|
# coding: utf-8
|
||
|
|
"""
|
||
|
|
主入口模块
|
||
|
|
支持单账户和多账户模式
|
||
|
|
"""
|
||
|
|
|
||
|
|
import json
|
||
|
|
import logging
|
||
|
|
import sys
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
from ticket_script import TicketBot, TicketConfig
|
||
|
|
|
||
|
|
logger = logging.getLogger("damai")
|
||
|
|
|
||
|
|
|
||
|
|
def load_config(path: str = "config/config.json") -> dict:
|
||
|
|
config_path = Path(path)
|
||
|
|
if not config_path.exists():
|
||
|
|
logger.error(f"配置文件不存在: {path}")
|
||
|
|
sys.exit(1)
|
||
|
|
with open(config_path, "r", encoding="utf-8") as f:
|
||
|
|
return json.load(f)
|
||
|
|
|
||
|
|
|
||
|
|
def run_single_account(config: dict):
|
||
|
|
"""单账户模式"""
|
||
|
|
tc = TicketConfig(
|
||
|
|
date=config["date"],
|
||
|
|
sess=config["sess"],
|
||
|
|
price=config["price"],
|
||
|
|
ticket_num=config.get("ticket_num", 2),
|
||
|
|
viewer_person=config.get("viewer_person", [1]),
|
||
|
|
nick_name=config.get("nick_name", ""),
|
||
|
|
damai_url=config.get("damai_url", "https://www.damai.cn/"),
|
||
|
|
target_url=config["target_url"],
|
||
|
|
driver_path=config["driver_path"],
|
||
|
|
max_retries=config.get("max_retries", 180),
|
||
|
|
retry_delay=config.get("retry_delay", 0.3),
|
||
|
|
)
|
||
|
|
|
||
|
|
bot = TicketBot(tc)
|
||
|
|
bot.run()
|
||
|
|
|
||
|
|
|
||
|
|
def run_multi_account(config: dict):
|
||
|
|
"""多账户模式"""
|
||
|
|
from scripts.multi_account_manager import load_accounts_from_config, run_parallel
|
||
|
|
|
||
|
|
accounts = load_accounts_from_config(config)
|
||
|
|
|
||
|
|
def account_task(acc_id, acc_info):
|
||
|
|
tc = TicketConfig(
|
||
|
|
date=config.get("date", [1]),
|
||
|
|
sess=config.get("sess", [1]),
|
||
|
|
price=config.get("price", [1]),
|
||
|
|
ticket_num=config.get("ticket_num", 2),
|
||
|
|
viewer_person=acc_info.viewer_person or [1],
|
||
|
|
nick_name=acc_info.username,
|
||
|
|
damai_url=config.get("damai_url", "https://www.damai.cn/"),
|
||
|
|
target_url=acc_info.target_url or config.get("target_url", ""),
|
||
|
|
driver_path=config.get("driver_path", ""),
|
||
|
|
max_retries=config.get("max_retries", 180),
|
||
|
|
retry_delay=config.get("retry_delay", 0.3),
|
||
|
|
)
|
||
|
|
bot = TicketBot(tc)
|
||
|
|
bot.run()
|
||
|
|
|
||
|
|
threads = run_parallel(accounts, account_task, max_workers=3)
|
||
|
|
|
||
|
|
for t in threads:
|
||
|
|
t.join()
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
logging.basicConfig(
|
||
|
|
level=logging.INFO,
|
||
|
|
format="%(asctime)s [%(levelname)s] %(message)s",
|
||
|
|
datefmt="%H:%M:%S",
|
||
|
|
)
|
||
|
|
|
||
|
|
config_path = sys.argv[1] if len(sys.argv) > 1 else "config/config.json"
|
||
|
|
config = load_config(config_path)
|
||
|
|
|
||
|
|
if isinstance(config.get("accounts"), (list, dict)):
|
||
|
|
run_multi_account(config)
|
||
|
|
else:
|
||
|
|
run_single_account(config)
|