diff --git a/src/plugins/hk_reporter/platform/arkninghts.py b/src/plugins/hk_reporter/platform/arkninghts.py new file mode 100644 index 0000000..cf650e3 --- /dev/null +++ b/src/plugins/hk_reporter/platform/arkninghts.py @@ -0,0 +1,43 @@ +import httpx +import json +import time +from collections import defaultdict +from bs4 import BeautifulSoup as bs +from datetime import datetime +from nonebot import logger + +from ..utils import Singleton, Render +from ..post import Post + +@Singleton +class Arknights: + + def __init__(self): + self.exists_posts = defaultdict(set) + self.inited = defaultdict(lambda: False) + + async def get_announce_list(self): + async with httpx.AsyncClient() as client: + raw_data = client.get('http://ak-fs.hypergryph.com/announce/IOS/announcement.meta.json') + return json.loads(raw_data.text) + + def filter(self, announce_data, inited=False) -> list[Post]: + announce_list = announce_data['announceList'] + res: list[Post] = [] + for announce in announce_list: + if inited: + self.exists_posts['default'].add(announce['announceId']) + continue + if announce['announceId'] in self.exists_posts['default']: + continue + res.append(await self.parse(announce['webUrl'])) + return res + + async def parse(self, announce_url: str) -> Post: + async with httpx.AsyncClient() as client: + raw_html = client.get(announce_url) + soup = bs(raw_html, 'html.parser') + if soup.find("div", class_="standerd-container"): + # 图文 + render = Render() + render. diff --git a/src/plugins/hk_reporter/utils.py b/src/plugins/hk_reporter/utils.py index cd0d4cf..6a128fc 100644 --- a/src/plugins/hk_reporter/utils.py +++ b/src/plugins/hk_reporter/utils.py @@ -16,7 +16,7 @@ class Singleton(type): cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) return cls._instances[cls] -supported_target_type = ('weibo', 'bilibili', 'rss') +supported_target_type = ('weibo', 'bilibili', 'rss', 'arknights') class Render(metaclass=Singleton):