34 lines
893 B
Python
Raw Normal View History

2024-11-24 14:48:49 +08:00
import traceback
import httpx
2024-11-24 14:48:49 +08:00
async def fetch_calendar():
url = "https://api.bgm.tv/calendar"
2024-11-24 14:48:49 +08:00
headers = {
"User-Agent": "LiteyukiStudio/nonebot-plugin-marshoai (https://github.com/LiteyukiStudio/nonebot-plugin-marshoai)"
2024-11-24 14:48:49 +08:00
}
async with httpx.AsyncClient() as client:
response = await client.get(url, headers=headers)
# print(response.text)
2024-11-24 14:48:49 +08:00
return response.json()
2024-11-24 14:48:49 +08:00
async def get_bangumi_news():
result = await fetch_calendar()
info = ""
try:
for i in result:
weekday = i["weekday"]["cn"]
# print(weekday)
2024-11-24 14:48:49 +08:00
info += f"{weekday}:"
items = i["items"]
for item in items:
name = item["name_cn"]
info += f"{name}"
info += "\n"
return info
except Exception as e:
traceback.print_exc()
return ""