import json from requests import get from pagermaid.listener import listener from pagermaid.utils import obtain_message icons = { "01d": "šŸŒž", "01n": "šŸŒš", "02d": "ā›…ļø", "02n": "ā›…ļø", "03d": "ā˜ļø", "03n": "ā˜ļø", "04d": "ā˜ļø", "04n": "ā˜ļø", "09d": "šŸŒ§", "09n": "šŸŒ§", "10d": "šŸŒ¦", "10n": "šŸŒ¦", "11d": "šŸŒ©", "11n": "šŸŒ©", "13d": "šŸŒØ", "13n": "šŸŒØ", "50d": "šŸŒ«", "50n": "šŸŒ«", } @listener(is_plugin=True, outgoing=True, command="weather", description="ęŸ„čÆ¢å¤©ę°”", parameters="<城åø‚>") async def weather(context): await context.edit("čŽ·å–äø­ . . .") try: message = await obtain_message(context) except ValueError: await context.edit("å‡ŗ错äŗ†å‘œå‘œå‘œ ~ ꗠꕈēš„å‚ę•°ć€‚") return req = get("http://api.openweathermap.org/data/2.5/weather?appid=973e8a21e358ee9d30b47528b43a8746&units=metric&lang=zh_cn&q=" + message) if req.status_code == 200: data = json.loads(req.text) cityName = "{}, {}".format(data["name"], data["sys"]["country"]) tempInC = round(data["main"]["temp"], 2) tempInF = round((1.8 * tempInC) + 32, 2) icon = data["weather"][0]["icon"] desc = data["weather"][0]["description"] res = "{}\nšŸŒ”{}ā„ƒ ({}F)\n{} {}".format( cityName, tempInC, tempInF, icons[icon], desc ) await context.edit(res) else: await context.edit("å‡ŗ错äŗ†å‘œå‘œå‘œ ~ ę— ę³•č®æ问到 openweathermap.org 怂")