소스 검색

优化查询设备天气接口

peng 2 년 전
부모
커밋
3c61a4b802
1개의 변경된 파일5개의 추가작업 그리고 5개의 파일을 삭제
  1. 5 5
      Controller/WeatherControl.py

+ 5 - 5
Controller/WeatherControl.py

@@ -51,14 +51,14 @@ class WeatherView(View):
         redis_obj = RedisObject()
         city_id = uid_set_qs[0]['tb_city_information_id']
         try:
-            temp = redis_obj.get_data('city_id_{}_temp'.format(city_id))
-            humidity = redis_obj.get_data('city_id_{}_humidity'.format(city_id))
-            if not all([temp, humidity]):
+            weather = redis_obj.get_data('city_id_{}_weather'.format(city_id))
+            if weather:
+                temp, humidity = weather.split('/')
+            else:
                 city_obj = WeatherInfo(city_id)
                 temp, humidity = city_obj.get_city_weather()
                 if temp and humidity:
-                    redis_obj.set_ex_data('city_id_{}_temp'.format(city_id), temp, 600)
-                    redis_obj.set_ex_data('city_id_{}_humidity'.format(city_id), humidity, 600)
+                    redis_obj.set_ex_data('city_id_{}_weather'.format(city_id), '{}/{}'.format(temp, humidity), 600)
             if not all([temp, humidity]):
                 return response.json(10, '获取天气失败')
             return response.json(0, {'temp': temp, 'humidity': humidity})