|
@@ -60,11 +60,10 @@ class WeatherView(View):
|
|
|
time_stamp = CommonService.str_to_timestamp(now_time.strftime('%Y-%m-%d %H:%M:%S'))
|
|
|
temp, humidity = None, None
|
|
|
try:
|
|
|
- weather = redis_obj.get_data('city_id_{}_{}_weather'.format(city_id, time_stamp))
|
|
|
+ weather = redis_obj.get_hash_data('city_id_{}_weather'.format(city_id), time_stamp)
|
|
|
if weather:
|
|
|
temp, humidity = weather.split('/')
|
|
|
else:
|
|
|
- LOGGER.info('redis不存在天气:{}'.format('city_id_{}_{}_weather'.format(city_id, time_stamp)))
|
|
|
city_obj = WeatherInfo(city_id)
|
|
|
weather_list = city_obj.get_city_24_weather()
|
|
|
if weather_list:
|
|
@@ -72,8 +71,9 @@ class WeatherView(View):
|
|
|
humidity = weather_list[0]['humidity']
|
|
|
for item in weather_list:
|
|
|
temp_time = CommonService.str_to_timestamp(item['date'] + ' ' + item['hour'] + ':00:00')
|
|
|
- redis_obj.set_ex_data('city_id_{}_{}_weather'.format(city_id, temp_time),
|
|
|
- '{}/{}'.format(item['temp'], item['humidity']), 86400)
|
|
|
+ redis_obj.set_hash_data('city_id_{}_weather'.format(city_id),
|
|
|
+ {temp_time: '{}/{}'.format(item['temp'], item['humidity'])})
|
|
|
+ redis_obj.set_expire('city_id_{}_weather'.format(city_id), 86400)
|
|
|
if not all([temp, humidity]):
|
|
|
return response.json(10, '获取天气失败')
|
|
|
return response.json(0, {'temp': temp, 'humidity': humidity})
|