-
Notifications
You must be signed in to change notification settings - Fork 315
Open
Labels
Description
例如
class LiveData:
"""直播数据类"""
def __init__(self, data: dict[Any, Any]):
"""初始化LiveInfo对象.
Args:
data (dict): API返回数据
"""
# 直播间信息
self.data: dict[Any, Any] = data # 原始数据
self.room_info: RoomInfo = RoomInfo(data["room_info"]) # 直播间信息
self.anchor_info: AnchorInfo = AnchorInfo(data["anchor_info"]) # 主播信息
self.watched_show: WatchedShow = WatchedShow(data["watched_show"]) # 观看人数信息
self.notice_board: NoticeBoard = NoticeBoard(data["news_info"]) # 公告栏信息
def __str__(self) -> str:
return f""使用类封装一些常用数据,也提供原始数据,方便调用
不过可能有违项目初衷,以及如果api数据结构更改的话会比较难维护,也或许有其他更简单的办法