PagerMaid_Plugins_Pyro/news/main.py

38 lines
1.3 KiB
Python
Raw Normal View History

from pyrogram import Client
2024-09-28 14:35:08 +00:00
from pagermaid.dependence import client
from pagermaid.enums import Message
from pagermaid.listener import listener
2023-07-01 12:18:58 +00:00
@listener(command="news", description="每日新闻、历史上的今天、天天成语、慧语香风、诗歌天地")
async def news(_: Client, context: Message):
msg = context.arguments
if not msg:
await context.edit("获取中 . . .")
try:
data = await client.get("https://news.topurl.cn/api")
data = data.json()["data"]
text = "📮 每日新闻 📮\n"
2023-07-01 12:18:58 +00:00
for idx, i in enumerate(data["newsList"]):
2023-06-11 08:53:19 +00:00
text += f"{idx + 1}. [{i['title']}]({i['url']})\n"
text += "\n🎬 历史上的今天 🎬\n"
for i in data["historyList"]:
text += f"{i['event']}\n"
text += "\n🧩 天天成语 🧩\n"
text += f"{data['phrase']['phrase']} ----{data['phrase']['explain']}\n"
text += "\n🎻 慧语香风 🎻\n"
text += f"{data['sentence']['sentence']} ----{data['sentence']['author']}\n"
text += "\n🎑 诗歌天地 🎑\n"
2023-07-01 12:18:58 +00:00
text += (
f"{''.join(data['poem']['content'])} "
f"----《{data['poem']['title']}{data['poem']['author']}"
)
await context.edit(text)
except Exception as e:
await context.edit(f"获取失败\n{e}")