MCPcopy Create free account
hub / github.com/Loping151/RoverSign / SigningState

Class SigningState

RoverSign/utils/sign_state.py:19–104  ·  view source on GitHub ↗

签到状态管理类

Source from the content-addressed store, hash-verified

17
18
19class SigningState:
20 """签到状态管理类"""
21
22 def __init__(self):
23 self.ensure_data_dir()
24
25 @staticmethod
26 def ensure_data_dir():
27 """确保数据目录存在"""
28 DATA_PATH.mkdir(parents=True, exist_ok=True)
29
30 @staticmethod
31 def is_signing() -> bool:
32 """检查是否正在签到"""
33 return STATE_FILE.exists()
34
35 @staticmethod
36 def get_state() -> Optional[dict]:
37 """获取当前签到状态。返回 {"type", "start_time"} 或 None。"""
38 if not STATE_FILE.exists():
39 return None
40
41 try:
42 with open(STATE_FILE, 'r', encoding='utf-8') as f:
43 state = json.load(f)
44 logger.debug(f"[库洛签到·签到状态] 读取状态文件: {state}")
45 return state
46 except Exception as e:
47 logger.error(f"[库洛签到·签到状态] 读取状态文件失败: {e}")
48 return None
49
50 @staticmethod
51 def set_state(sign_type: SignType):
52 """设置签到状态。"""
53 state = {
54 "type": sign_type,
55 "start_time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
56 }
57 try:
58 with open(STATE_FILE, 'w', encoding='utf-8') as f:
59 json.dump(state, f, ensure_ascii=False, indent=2)
60 logger.info(f"[库洛签到·签到状态] 创建状态文件: type={sign_type}")
61 except Exception as e:
62 logger.error(f"[库洛签到·签到状态] 创建状态文件失败: {e}")
63
64 @staticmethod
65 def clear_state():
66 """清除签到状态(签到完成时调用)"""
67 if STATE_FILE.exists():
68 try:
69 STATE_FILE.unlink()
70 logger.info("[库洛签到·签到状态] 删除状态文件(签到已完成)")
71 except Exception as e:
72 logger.error(f"[库洛签到·签到状态] 删除状态文件失败: {e}")
73
74 @staticmethod
75 def should_resume() -> bool:
76 """

Callers 1

sign_state.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected