PagerMaid_Plugins_Pyro/weather_lite/main.py

26 lines
1004 B
Python
Raw Normal View History

2022-07-22 07:53:53 +00:00
from pagermaid.listener import listener
2022-09-01 12:30:34 +00:00
from pagermaid.enums import Message, AsyncClient
2024-09-28 14:35:08 +00:00
from pagermaid.utils import safe_remove
2022-07-22 07:53:53 +00:00
2023-07-01 12:18:58 +00:00
@listener(command="weather_lite", description="查询天气", parameters="[城市]")
2022-09-01 12:30:34 +00:00
async def weather_lite(request: AsyncClient, message: Message):
2022-07-22 07:53:53 +00:00
if not message.arguments:
return await message.edit("请输入城市名称")
if message.arguments.startswith("_"):
return await message.edit("请输入正确的城市名称")
city = message.arguments.strip()
2022-09-01 12:30:34 +00:00
data = await request.get(f"https://zh.wttr.in/{city}.png")
2022-07-22 07:53:53 +00:00
if data.status_code != 200:
return await message.edit("请输入正确的城市名称")
with open("weather.png", "wb") as f:
f.write(data.content)
2022-11-18 08:41:46 +00:00
await message.reply_photo(
"weather.png",
2024-02-04 07:56:06 +00:00
reply_to_message_id=message.reply_to_message_id,
message_thread_id=message.message_thread_id,
2023-07-01 12:18:58 +00:00
quote=False,
2022-11-18 08:41:46 +00:00
)
2022-07-22 07:53:53 +00:00
await message.safe_delete()
safe_remove("weather.png")