|
@@ -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})
|