From b95fe5aebf50553548c3ca317d55c8e6133457a6 Mon Sep 17 00:00:00 2001 From: ZhehaoMi <1125263974@qq.com> Date: Wed, 20 Feb 2019 14:35:24 +0800 Subject: [PATCH] weather --- .../{whether => weather}/config_default.py | 0 .../whether.py => weather/weather.py} | 28 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) rename plugins/{whether => weather}/config_default.py (100%) rename plugins/{whether/whether.py => weather/weather.py} (73%) diff --git a/plugins/whether/config_default.py b/plugins/weather/config_default.py similarity index 100% rename from plugins/whether/config_default.py rename to plugins/weather/config_default.py diff --git a/plugins/whether/whether.py b/plugins/weather/weather.py similarity index 73% rename from plugins/whether/whether.py rename to plugins/weather/weather.py index afbce71..f1902fe 100644 --- a/plugins/whether/whether.py +++ b/plugins/weather/weather.py @@ -11,7 +11,7 @@ def plugin(): "description": "天气查询" } -def get_now_whether(local, key): +def get_now_weather(local, key): url = "https://free-api.heweather.net/s6/weather/now?location=%s&key=%s" % (str(urllib.parse.quote(local)), key) import json data = None @@ -27,7 +27,7 @@ def get_air(local, key): data = json.JSONDecoder().decode(f.read().decode("utf-8")) return data['HeWeather6'][0] -def get_forecast_whether(local, key): +def get_forecast_weather(local, key): url = "https://free-api.heweather.net/s6/weather/forecast?location=%s&key=%s" % (str(urllib.parse.quote(local)), key) import json data = None @@ -36,33 +36,33 @@ def get_forecast_whether(local, key): return data['HeWeather6'][0] @command(name="天气", help="查询天气") -def whether(bot, context, args): +def weather(bot, context, args): while args[-1] == "": del args[-1] def handle(): - now_whether = get_now_whether(args[1], config.KEY) - forecast_whether = get_forecast_whether(args[1], config.KEY) + now_weather = get_now_weather(args[1], config.KEY) + forecast_weather = get_forecast_weather(args[1], config.KEY) - if not now_whether['status'] == "ok": - bot.send(context,"Error: %s"% now_whether['status']) + if not now_weather['status'] == "ok": + bot.send(context,"Error: %s"% now_weather['status']) return - now_air = get_air(now_whether['basic']['parent_city'], config.KEY) + now_air = get_air(now_weather['basic']['parent_city'], config.KEY) location_data = "查询位置:%s,%s,%s,%s\n时区:%s\n更新时间:%s\n" % ( - now_whether['basic']['location'], now_whether['basic']['parent_city'], - now_whether['basic']['admin_area'], now_whether['basic']['cnty'], - now_whether['basic']['tz'], now_whether['update']['loc']) + now_weather['basic']['location'], now_weather['basic']['parent_city'], + now_weather['basic']['admin_area'], now_weather['basic']['cnty'], + now_weather['basic']['tz'], now_weather['update']['loc']) now_data = "当前天气:%s\n当前温度:%s摄氏度\n风向风力:%s %s级\n空气质量:%s\n空气质量指数(AQI):%s\n" % ( - now_whether['now']['cond_txt'], now_whether['now']['tmp'], - now_whether['now']['wind_dir'], now_whether['now']['wind_sc'], + now_weather['now']['cond_txt'], now_weather['now']['tmp'], + now_weather['now']['wind_dir'], now_weather['now']['wind_sc'], now_air['air_now_city']['qlty'], now_air['air_now_city']['aqi']) more_days = [] - for item in forecast_whether['daily_forecast']: + for item in forecast_weather['daily_forecast']: more_days.append("天(%s):\n白天天气:%s\n夜间天气:%s\n最高温度:%s摄氏度\n最低温度:%s摄氏度" %( item['date'],item['cond_txt_d'],item['cond_txt_n'],item['tmp_max'],item['tmp_min'] )) -- Gitee