From 7df86e0ead8c6086e078f6ca6988f4fd265a32e8 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 22 Jul 2022 15:53:53 +0800 Subject: [PATCH] =?UTF-8?q?weather=5Flite=20=E6=9F=A5=E8=AF=A2=E5=A4=A9?= =?UTF-8?q?=E6=B0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- list.json | 10 ++++++++++ weather_lite/main.py | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 weather_lite/main.py diff --git a/list.json b/list.json index 8f4b94e..6404058 100644 --- a/list.json +++ b/list.json @@ -439,6 +439,16 @@ "supported": true, "des-short": "一言。", "des": "一言。\n指令:,hitokoto" + }, + { + "name": "weather_lite", + "version": "1.0", + "section": "daily", + "maintainer": "xtaodada", + "size": "0.97 kb", + "supported": true, + "des-short": "查询天气。", + "des": "查询天气。指令:,weather_lite" } ] } diff --git a/weather_lite/main.py b/weather_lite/main.py new file mode 100644 index 0000000..91a5fbb --- /dev/null +++ b/weather_lite/main.py @@ -0,0 +1,23 @@ +from pagermaid.listener import listener +from pagermaid.single_utils import Message, safe_remove + + +@listener(command="weather_lite", + description="查询天气", + parameters="<城市>") +async def weather_lite(message: Message): + if not message.arguments: + return await message.edit("请输入城市名称") + if message.arguments.startswith("_"): + return await message.edit("请输入正确的城市名称") + city = message.arguments.strip() + data = await message.request.get(f"https://zh.wttr.in/{city}.png") + if data.status_code != 200: + return await message.edit("请输入正确的城市名称") + with open("weather.png", "wb") as f: + f.write(data.content) + await message.reply_photo("weather.png", + reply_to_message_id=message.reply_to_message_id, + quote=False) + await message.safe_delete() + safe_remove("weather.png")