add save and load func

This commit is contained in:
bridge
2025-11-11 19:48:18 +08:00
parent 0cb7eacee7
commit 9b870475bf
21 changed files with 1348 additions and 32 deletions

View File

@@ -17,6 +17,23 @@ class Event:
year = self.month_stamp.get_year()
month = self.month_stamp.get_month()
return f"{year}{month}月: {self.content}"
def to_dict(self) -> dict:
"""转换为可序列化的字典"""
return {
"month_stamp": int(self.month_stamp),
"content": self.content,
"related_avatars": self.related_avatars
}
@classmethod
def from_dict(cls, data: dict) -> "Event":
"""从字典重建Event"""
return cls(
month_stamp=MonthStamp(data["month_stamp"]),
content=data["content"],
related_avatars=data.get("related_avatars")
)
class NullEvent:
"""