mirror of
https://github.com/LiteyukiStudio/nonebot-plugin-marshoai.git
synced 2024-12-05 03:34:53 +08:00
29 lines
886 B
Python
29 lines
886 B
Python
import httpx
|
|
import traceback
|
|
async def fetch_calendar():
|
|
url = 'https://api.bgm.tv/calendar'
|
|
headers = {
|
|
'User-Agent': 'LiteyukiStudio/nonebot-plugin-marshoai (https://github.com/LiteyukiStudio/nonebot-plugin-marshoai)'
|
|
}
|
|
async with httpx.AsyncClient() as client:
|
|
response = await client.get(url, headers=headers)
|
|
#print(response.text)
|
|
return response.json()
|
|
|
|
async def get_bangumi_news():
|
|
result = await fetch_calendar()
|
|
info = ""
|
|
try:
|
|
for i in result:
|
|
weekday = i["weekday"]["cn"]
|
|
#print(weekday)
|
|
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 "" |