Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/meme/moegirl.py

34 lines
2.3 KiB
Python
Raw Normal View History

2022-01-08 14:03:09 +00:00
import re
2022-01-20 12:13:03 +00:00
from modules.wiki import query_pages
from modules.wiki.wikilib_v2 import QueryInfo
2022-01-03 09:13:42 +00:00
async def moegirl(term: str):
2022-01-07 15:01:15 +00:00
result = await query_pages(QueryInfo('https://zh.moegirl.org.cn/api.php', headers={'accept': '*/*',
2022-01-18 04:06:09 +00:00
'accept-encoding': 'gzip, deflate',
'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,en-GB;q=0.6',
'content-type': 'application/json',
2022-01-20 12:13:03 +00:00
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/96.0.1054.62'}),
term)
msg = ''
if result['msg_list']:
for msg_item in result['msg_list']:
msg += msg_item.text
if result['wait_msg_list']:
for msg_item in result['wait_msg_list']:
2022-01-08 14:03:09 +00:00
print('msg_item.text: ', msg_item.text)
2022-01-18 04:06:09 +00:00
redirect = re.search(
r'(?<=是:\[)(.*?)(?=\]。)', msg_item.text).group(0)
2022-01-08 14:03:09 +00:00
print(redirect)
if redirect:
wait = await query_pages(QueryInfo('https://zh.moegirl.org.cn/api.php', headers={'accept': '*/*',
2022-01-18 04:06:09 +00:00
'accept-encoding': 'gzip, deflate',
'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,en-GB;q=0.6',
'content-type': 'application/json',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/96.0.1054.62'
}), redirect)
2022-01-08 14:03:09 +00:00
msg += wait['msg_list'][0].text
return '[萌娘百科] ' + msg