Kaynağa Gözat

优化查询天气接口

peng 2 yıl önce
ebeveyn
işleme
4af99d590d
2 değiştirilmiş dosya ile 3 ekleme ve 1 silme
  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:
             city_obj = WeatherInfo(uid_set_qs[0]['tb_city_information_id'])
             temp, humidity = city_obj.get_city_weather()
+            if not all([temp, humidity]):
+                return response.json(10, '获取天气失败')
             return response.json(0, {'temp': temp, 'humidity': humidity})
         except Exception as e:
             print(e)

+ 1 - 1
Object/IPWeatherObject.py

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