diff options
author | Kyomotoi <[email protected]> | 2022-06-13 19:37:34 +0800 |
---|---|---|
committer | Kyomotoi <[email protected]> | 2022-06-13 19:37:34 +0800 |
commit | 59c923bbc3e91ad5a3482ec81c9192297ebbebe8 (patch) | |
tree | d74da226542a8b6f54200bd6d55e8d459315c71d /ATRI/plugins/bilibili_dynamic/api.py | |
parent | 4a876e2e64a690dcf01c385e273052e1e22caacd (diff) | |
download | ATRI-59c923bbc3e91ad5a3482ec81c9192297ebbebe8.tar.gz ATRI-59c923bbc3e91ad5a3482ec81c9192297ebbebe8.tar.bz2 ATRI-59c923bbc3e91ad5a3482ec81c9192297ebbebe8.zip |
♻️ 重构插件: b站动态订阅
Diffstat (limited to 'ATRI/plugins/bilibili_dynamic/api.py')
-rw-r--r-- | ATRI/plugins/bilibili_dynamic/api.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/ATRI/plugins/bilibili_dynamic/api.py b/ATRI/plugins/bilibili_dynamic/api.py new file mode 100644 index 0000000..a455805 --- /dev/null +++ b/ATRI/plugins/bilibili_dynamic/api.py @@ -0,0 +1,36 @@ +from ATRI.utils import request +from ATRI.exceptions import RequestError + + +class API: + def __init__(self, uid: int): + self.uid = uid + + async def _request(self, url: str, params: dict = dict()) -> dict: + headers = { + "Referer": "https://www.bilibili.com", + "User-Agent": "Mozilla/5.0", + } + + try: + resp = await request.get(url, params=params, headers=headers) + except RequestError: + raise RequestError("Request failed!") + + return resp.json() + + async def get_user_info(self) -> dict: + url = "https://api.bilibili.com/x/space/acc/info" + params = {"mid": self.uid} + return await self._request(url, params) + + async def get_user_dynamics( + self, offset: int = int(), need_top: bool = False + ) -> dict: + url = "https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history" + params = { + "host_uid": self.uid, + "offset_dynamic_id": offset, + "need_top": 1 if need_top else 0, + } + return await self._request(url, params) |