PagerMaid_Plugins/resou.py

85 lines
3.4 KiB
Python
Raw Permalink Normal View History

2020-08-12 10:55:52 +00:00
import json
from requests import get
from json.decoder import JSONDecodeError
2022-01-18 08:47:20 +00:00
from pagermaid import version
2020-08-12 10:55:52 +00:00
from pagermaid.listener import listener
2021-06-16 07:09:40 +00:00
from pagermaid.utils import alias_command
2020-08-12 10:55:52 +00:00
2021-06-16 07:09:40 +00:00
@listener(is_plugin=True, outgoing=True, command=alias_command("zhrs"),
2020-08-12 10:55:52 +00:00
description="知乎热搜。")
async def zhrs(context):
2020-08-12 10:55:52 +00:00
await context.edit("获取中 . . .")
req = get("https://tenapi.cn/zhihuresou")
if req.status_code == 200:
try:
data = json.loads(req.text)
except JSONDecodeError:
await context.edit("出错了呜呜呜 ~ API 数据解析失败。")
return
res = '知乎实时热搜榜:\n'
for i in range(0, 10):
res += f'\n{i + 1}.「<a href={data["list"][i]["url"]}>{data["list"][i]["query"]}</a>」'
2020-08-12 10:55:52 +00:00
await context.edit(res, parse_mode='html', link_preview=False)
else:
await context.edit("出错了呜呜呜 ~ 无法访问到 API 服务器 。")
2021-06-16 07:09:40 +00:00
@listener(is_plugin=True, outgoing=True, command=alias_command("wbrs"),
2020-08-12 10:55:52 +00:00
description="微博热搜。")
async def wbrs(context):
2020-08-12 10:55:52 +00:00
await context.edit("获取中 . . .")
req = get("https://tenapi.cn/resou")
if req.status_code == 200:
try:
data = json.loads(req.text)
except JSONDecodeError:
await context.edit("出错了呜呜呜 ~ API 数据解析失败。")
return
res = '微博实时热搜榜:\n'
for i in range(0, 10):
res += f'\n{i + 1}.「<a href={data["list"][i]["url"]}>{data["list"][i]["name"]}</a>」 ' \
f'热度:{data["list"][i]["hot"]}'
2020-08-12 10:55:52 +00:00
await context.edit(res, parse_mode='html', link_preview=True)
else:
await context.edit("出错了呜呜呜 ~ 无法访问到 API 服务器 。")
2021-06-16 07:09:40 +00:00
@listener(is_plugin=True, outgoing=True, command=alias_command("dyrs"),
2020-08-12 10:55:52 +00:00
description="抖音热搜。")
async def dyrs(context):
2020-08-12 10:55:52 +00:00
await context.edit("获取中 . . .")
req = get("https://tenapi.cn/douyinresou")
if req.status_code == 200:
try:
data = json.loads(req.text)
except JSONDecodeError:
await context.edit("出错了呜呜呜 ~ API 数据解析失败。")
return
res = '抖音实时热搜榜:\n'
for i in range(0, 10):
res += f'\n{i + 1}.「{data["list"][i]["name"]}」 热度:{data["list"][i]["hot"]}'
2020-08-12 10:55:52 +00:00
await context.edit(res, parse_mode='html', link_preview=True)
else:
await context.edit("出错了呜呜呜 ~ 无法访问到 API 服务器 。")
2020-08-12 13:55:15 +00:00
2021-06-16 07:09:40 +00:00
@listener(is_plugin=True, outgoing=True, command=alias_command("brank"),
2020-08-12 13:55:15 +00:00
description="B站排行榜。")
async def brank(context):
await context.edit("获取中 . . .")
req = get("https://api.imjad.cn/bilibili/v2/?get=rank&type=all")
if req.status_code == 200:
try:
data = json.loads(req.content)['rank']['list']
except JSONDecodeError:
await context.edit("出错了呜呜呜 ~ API 数据解析失败。")
return
res = 'B站实时排行榜\n'
for i in range(0, 10):
res += f'\n{i + 1}.「<a href="https://www.bilibili.com/video/{data[i]["bvid"]}">{data[i]["title"]}</a>」 - ' \
f'{data[i]["author"]}'
await context.edit(res, parse_mode='html', link_preview=False)
2020-08-12 13:55:15 +00:00
else:
2021-06-16 07:09:40 +00:00
await context.edit("出错了呜呜呜 ~ 无法访问到 API 服务器 。")