瀏覽代碼

优化查询天气接口

peng 2 年之前
父節點
當前提交
4af99d590d
共有 2 個文件被更改,包括 3 次插入1 次删除
  1. 2 0
      Controller/WeatherControl.py
  2. 1 1
      Object/IPWeatherObject.py

+ 2 - 0
Controller/WeatherControl.py

@@ -50,6 +50,8 @@ class WeatherView(View):
         try:
         try:
             city_obj = WeatherInfo(uid_set_qs[0]['tb_city_information_id'])
             city_obj = WeatherInfo(uid_set_qs[0]['tb_city_information_id'])
             temp, humidity = city_obj.get_city_weather()
             temp, humidity = city_obj.get_city_weather()
+            if not all([temp, humidity]):
+                return response.json(10, '获取天气失败')
             return response.json(0, {'temp': temp, 'humidity': humidity})
             return response.json(0, {'temp': temp, 'humidity': humidity})
         except Exception as e:
         except Exception as e:
             print(e)
             print(e)

+ 1 - 1
Object/IPWeatherObject.py

@@ -49,4 +49,4 @@ class WeatherInfo:
                 # 返回温湿度
                 # 返回温湿度
                 return '{} ℃'.format(result['data']['condition']['temp']), '{} %'.format(
                 return '{} ℃'.format(result['data']['condition']['temp']), '{} %'.format(
                     result['data']['condition']['humidity'])
                     result['data']['condition']['humidity'])
-        return False
+        return None, None