accuweather полноценно работает (доделал получение погоды на завтра и сегодня).
Код для погоды на сегодня и завтра сильно упростил. Старый код вообще никуда не годился.
Под спойлерами код получения погоды на завтра.
if show_block_tomorrow:
#### weather tomorrow ####
source = ['', '', '', '']
for i, w_time in zip(range(4), ['morning', 'afternoon', 'evening', 'overnight']):
source[i] = urlopener('http://www.accuweather.com/en/%s/%s-weather-forecast/%s?day=2'%(city_id, w_time, city_number), 5)
if not source[i]:
return False
t_tomorrow=[]
t_tomorrow_low = []
icon_tomorrow = []
for s in source:
w_now = re.findall('detail-now.*', s, re.DOTALL)
t = re.findall('<span class="large-temp">(.?\d+)', w_now[0])
if not celsius:
t[0] = F_to_C(t[0])
t[0] = convert_from_C(t[0])
t_tomorrow.append(t[0])
t = re.findall('<span class="small-temp">/(.?\d+)', w_now[0])
if not celsius:
t[0] = F_to_C(t[0])
t[0] = convert_from_C(t[0])
t_tomorrow_low.append(t[0])
i = re.findall('<div class="icon (.*)xl"', w_now[0])
i[0] = convert(i[0], icons_name)
icon_tomorrow.append(i[0])
if show_block_tomorrow:
#### weather tomorrow ####
w_night = urlopener('http://www.accuweather.com/en/%s/overnight-weather-forecast/%s?day=2'%(city_id, city_number), 5)
if not w_night:
return False
time.sleep(1)
w_morning = urlopener('http://www.accuweather.com/en/%s/morning-weather-forecast/%s?day=2'%(city_id, city_number), 5)
if not w_morning:
return False
time.sleep(1)
w_day = urlopener('http://www.accuweather.com/en/%s/afternoon-weather-forecast/%s?day=2'%(city_id, city_number), 5)
if not w_day:
return False
time.sleep(1)
w_evening = urlopener('http://www.accuweather.com/en/%s/evening-weather-forecast/%s?day=2'%(city_id, city_number), 5)
if not w_evening:
return False
time.sleep(1)
t_tomorrow=[]
t = re.findall('<span class="temp">(.?\d+)<', w_morning)
if t[0][0] not in ('+', '-', '0'):
t[0] = '+'+t[0]
if not celsius:
t[0] = F_to_C(t[0])
t[0] = t[0]+'°;'+t[0]+'°;'+C_to_F(t[0])+'°;'+C_to_F(t[0])+'°;'+C_to_K(t[0])+';'+C_to_K(t[0])
t_tomorrow.append(t[0])
t = re.findall('<span class="temp">(.?\d+)<', w_day)
if t[0][0] not in ('+', '-', '0'):
t[0] = '+'+t[0]
if not celsius:
t[0] = F_to_C(t[0])
t[0] = t[0]+'°;'+t[0]+'°;'+C_to_F(t[0])+'°;'+C_to_F(t[0])+'°;'+C_to_K(t[0])+';'+C_to_K(t[0])
t_tomorrow.append(t[0])
t = re.findall('<span class="temp">(.?\d+)<', w_evening)
if t[0][0] not in ('+', '-', '0'):
t[0] = '+'+t[0]
if not celsius:
t[0] = F_to_C(t[0])
t[0] = t[0]+'°;'+t[0]+'°;'+C_to_F(t[0])+'°;'+C_to_F(t[0])+'°;'+C_to_K(t[0])+';'+C_to_K(t[0])
t_tomorrow.append(t[0])
t = re.findall('<span class="temp">(.?\d+)<', w_night)
if t[0][0] not in ('+', '-', '0'):
t[0] = '+'+t[0]
if not celsius:
t[0] = F_to_C(t[0])
t[0] = t[0]+'°;'+t[0]+'°;'+C_to_F(t[0])+'°;'+C_to_F(t[0])+'°;'+C_to_K(t[0])+';'+C_to_K(t[0])
t_tomorrow.append(t[0])
t_tomorrow_low = []
t = re.findall('<span class="lo">Lo (.?\d+)<', w_morning)
if t[0][0] not in ('+', '-', '0'):
t[0] = '+'+t[0]
if not celsius:
t[0] = F_to_C(t[0])
t[0] = t[0]+'°;'+t[0]+'°;'+C_to_F(t[0])+'°;'+C_to_F(t[0])+'°;'+C_to_K(t[0])+';'+C_to_K(t[0])
t_tomorrow_low.append(t[0])
t = re.findall('<span class="lo">Lo (.?\d+)<', w_day)
if t[0][0] not in ('+', '-', '0'):
t[0] = '+'+t[0]
if not celsius:
t[0] = F_to_C(t[0])
t[0] = t[0]+'°;'+t[0]+'°;'+C_to_F(t[0])+'°;'+C_to_F(t[0])+'°;'+C_to_K(t[0])+';'+C_to_K(t[0])
t_tomorrow_low.append(t[0])
t = re.findall('<span class="lo">Lo (.?\d+)<', w_evening)
if t[0][0] not in ('+', '-', '0'):
t[0] = '+'+t[0]
if not celsius:
t[0] = F_to_C(t[0])
t[0] = t[0]+'°;'+t[0]+'°;'+C_to_F(t[0])+'°;'+C_to_F(t[0])+'°;'+C_to_K(t[0])+';'+C_to_K(t[0])
t_tomorrow_low.append(t[0])
t = re.findall('<span class="lo">Lo (.?\d+)<', w_night)
if t[0][0] not in ('+', '-', '0'):
t[0] = '+'+t[0]
if not celsius:
t[0] = F_to_C(t[0])
t[0] = t[0]+'°;'+t[0]+'°;'+C_to_F(t[0])+'°;'+C_to_F(t[0])+'°;'+C_to_K(t[0])+';'+C_to_K(t[0])
t_tomorrow_low.append(t[0])
icon_tomorrow = []
i = re.findall('<div class="forecast">\s*<div class="icon (.*)"></div>', w_morning)
i[0] = i[0][2:-2]
if len(i[0])==2:
i[0]='0'+i[0]
i[0] = 'http://vortex.accuweather.com/adc2010/images/icons-numbered/'+i[0]+'h.png'
i[0] = convert(i[0], icons_name)
icon_tomorrow.append(i[0])
i = re.findall('<div class="forecast">\s*<div class="icon (.*)"></div>', w_day)
i[0] = i[0][2:-2]
if len(i[0])==2:
i[0]='0'+i[0]
i[0] = 'http://vortex.accuweather.com/adc2010/images/icons-numbered/'+i[0]+'h.png'
i[0] = convert(i[0], icons_name)
icon_tomorrow.append(i[0])
i = re.findall('<div class="forecast">\s*<div class="icon (.*)"></div>', w_evening)
i[0] = i[0][2:-2]
if len(i[0])==2:
i[0]='0'+i[0]
i[0] = 'http://vortex.accuweather.com/adc2010/images/icons-numbered/'+i[0]+'h.png'
i[0] = convert(i[0], icons_name)
icon_tomorrow.append(i[0])
i = re.findall('<div class="forecast">\s*<div class="icon (.*)"></div>', w_night)
i[0] = i[0][2:-2]
if len(i[0])==2:
i[0]='0'+i[0]
i[0] = 'http://vortex.accuweather.com/adc2010/images/icons-numbered/'+i[0]+'h.png'
i[0] = convert(i[0], icons_name)
icon_tomorrow.append(i[0])