mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-04 02:26:11 +08:00
add arkninghts
This commit is contained in:
parent
66f0de8f1d
commit
1afa13485f
@ -9,8 +9,7 @@ from nonebot import logger
|
|||||||
from ..utils import Singleton, Render
|
from ..utils import Singleton, Render
|
||||||
from ..post import Post
|
from ..post import Post
|
||||||
|
|
||||||
@Singleton
|
class Arknights(metaclass=Singleton):
|
||||||
class Arknights:
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.exists_posts = defaultdict(set)
|
self.exists_posts = defaultdict(set)
|
||||||
@ -21,7 +20,7 @@ class Arknights:
|
|||||||
raw_data = client.get('http://ak-fs.hypergryph.com/announce/IOS/announcement.meta.json')
|
raw_data = client.get('http://ak-fs.hypergryph.com/announce/IOS/announcement.meta.json')
|
||||||
return json.loads(raw_data.text)
|
return json.loads(raw_data.text)
|
||||||
|
|
||||||
def filter(self, announce_data, inited=False) -> list[Post]:
|
async def filter(self, announce_data, inited=False) -> list[Post]:
|
||||||
announce_list = announce_data['announceList']
|
announce_list = announce_data['announceList']
|
||||||
res: list[Post] = []
|
res: list[Post] = []
|
||||||
for announce in announce_list:
|
for announce in announce_list:
|
||||||
@ -31,13 +30,36 @@ class Arknights:
|
|||||||
if announce['announceId'] in self.exists_posts['default']:
|
if announce['announceId'] in self.exists_posts['default']:
|
||||||
continue
|
continue
|
||||||
res.append(await self.parse(announce['webUrl']))
|
res.append(await self.parse(announce['webUrl']))
|
||||||
|
if None in res:
|
||||||
|
res.remove(None)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
async def parse(self, announce_url: str) -> Post:
|
async def parse(self, announce_url: str) -> Post:
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
raw_html = client.get(announce_url)
|
raw_html = client.get(announce_url)
|
||||||
soup = bs(raw_html, 'html.parser')
|
soup = bs(raw_html, 'html.parser')
|
||||||
|
pics = []
|
||||||
if soup.find("div", class_="standerd-container"):
|
if soup.find("div", class_="standerd-container"):
|
||||||
# 图文
|
# 图文
|
||||||
render = Render()
|
render = Render()
|
||||||
render.
|
viewport = {'width': 320, 'height': 6400, 'deviceScaleFactor': 3}
|
||||||
|
pic_data = await render.render(announce_url, viewport=viewport, target='div.main')
|
||||||
|
pics.append('base64://{}'.format(pic_data))
|
||||||
|
elif (pic := soup.find('img', class_='banner-image')):
|
||||||
|
pics.append(pic['src'])
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
async def fetch_new_post(self, _) -> list[Post]:
|
||||||
|
try:
|
||||||
|
data = await self.get_announce_list()
|
||||||
|
if self.inited['default'] or True:
|
||||||
|
return await self.filter(data)
|
||||||
|
else:
|
||||||
|
await self.filter(data, True)
|
||||||
|
self.inited['default'] = True
|
||||||
|
return []
|
||||||
|
except httpx.RequestError as err:
|
||||||
|
logger.warning("network connection error: {}, url: {}".format(type(err), err.request.url))
|
||||||
|
return []
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ from collections import defaultdict
|
|||||||
from .weibo import Weibo, get_user_info as weibo_user_info
|
from .weibo import Weibo, get_user_info as weibo_user_info
|
||||||
from .bilibili import Bilibili, get_user_info as bilibili_user_info
|
from .bilibili import Bilibili, get_user_info as bilibili_user_info
|
||||||
from .rss import Rss, get_rss_info as rss_info
|
from .rss import Rss, get_rss_info as rss_info
|
||||||
|
from .arkninghts import Arknights
|
||||||
from ..config import Config
|
from ..config import Config
|
||||||
from ..post import Post
|
from ..post import Post
|
||||||
from ..send import send_msgs
|
from ..send import send_msgs
|
||||||
@ -17,6 +18,8 @@ async def check_sub_target(target_type, target):
|
|||||||
return await bilibili_user_info(target)
|
return await bilibili_user_info(target)
|
||||||
elif target_type == 'rss':
|
elif target_type == 'rss':
|
||||||
return await rss_info(target)
|
return await rss_info(target)
|
||||||
|
elif target_type == 'arknights':
|
||||||
|
return '明日方舟游戏公告'
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -35,7 +38,8 @@ async def fetch_and_send(target_type: str):
|
|||||||
platform_manager = {
|
platform_manager = {
|
||||||
'bilibili': Bilibili(),
|
'bilibili': Bilibili(),
|
||||||
'weibo': Weibo(),
|
'weibo': Weibo(),
|
||||||
'rss': Rss()
|
'rss': Rss(),
|
||||||
|
'arkninghts': Arknights()
|
||||||
}
|
}
|
||||||
target = config.get_next_target(target_type)
|
target = config.get_next_target(target_type)
|
||||||
if not target:
|
if not target:
|
||||||
|
@ -18,6 +18,10 @@ async def bilibili_check():
|
|||||||
async def rss_check():
|
async def rss_check():
|
||||||
await fetch_and_send('rss')
|
await fetch_and_send('rss')
|
||||||
|
|
||||||
|
@scheduler.scheduled_job('interval', seconds=30)
|
||||||
|
async def arknights_check():
|
||||||
|
await fetch_and_send('arknights')
|
||||||
|
|
||||||
@scheduler.scheduled_job('interval', seconds=1)
|
@scheduler.scheduled_job('interval', seconds=1)
|
||||||
async def _():
|
async def _():
|
||||||
await do_send_msgs()
|
await do_send_msgs()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user