|
@@ -62,6 +62,7 @@ class WeatherView(View):
|
|
|
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:
|
|
@@ -69,10 +70,8 @@ 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')
|
|
|
- result = redis_obj.set_ex_data('city_id_{}_{}_weather'.format(city_id, temp_time),
|
|
|
- '{}/{}'.format(item['temp'], item['humidity']), 86400)
|
|
|
- if not result:
|
|
|
- LOGGER.info('写入天气失败:{}'.format(item))
|
|
|
+ redis_obj.set_ex_data('city_id_{}_{}_weather'.format(city_id, temp_time),
|
|
|
+ '{}/{}'.format(item['temp'], item['humidity']), 86400)
|
|
|
if not all([temp, humidity]):
|
|
|
return response.json(10, '获取天气失败')
|
|
|
return response.json(0, {'temp': temp, 'humidity': humidity})
|