mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-02 09:26:12 +08:00
add game announce
This commit is contained in:
parent
70551e23b8
commit
66f0de8f1d
43
src/plugins/hk_reporter/platform/arkninghts.py
Normal file
43
src/plugins/hk_reporter/platform/arkninghts.py
Normal file
@ -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.
|
@ -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):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user