Beispiel #1
0
def get_weather():
    global w, sunrise, sunset, sun_duration, moonrise, moonset, moon_duration, URL, URL_HOURLY, URL_DAILY, city_name, t_now, wind_speed_now, wind_direct_now, icon_now, icon_wind_now, time_update, text_now, press_now, hum_now, t_water_now, t_night, t_night_feel, day, date, t_day, t_day_feel, icon, icon_wind, wind_speed, wind_direct, text, t_tomorrow, t_tomorrow_feel, icon_tomorrow, wind_speed_tom, wind_direct_tom, t_today, t_today_feel, icon_today, wind_speed_tod, wind_direct_tod, chance_of_rain, t_today_low, t_tomorrow_low
    n = gw_vars.get('n')
    city_id = gw_vars.get('city_id')
    show_block_tomorrow = gw_vars.get('show_block_tomorrow')
    show_block_today = gw_vars.get('show_block_today')
    show_block_add_info = gw_vars.get('show_block_add_info')
    weather_lang = gw_vars.get('weather_lang')
    icons_name = gw_vars.get('icons_name')
    if city_id.split(',')[0]==city_id.split(',')[-1]:
        city_number = city_id.split('/')[-1]
    else:
        city_number = city_id.split(',')[-1].strip()
        city_id = city_id.split(',')[0].strip()
    URL_CURRENT = 'http://www.accuweather.com/%s/%s/current-weather/%s'%(weather_lang, city_id, city_number)
    URL_ADD_INFO = 'http://www.accuweather.com/en/%s/current-weather/%s'%(city_id, city_number)
    URL_SEVERAL_DAYS = 'http://www.accuweather.com/%s/%s/month/%s?view=table'%(weather_lang, city_id, city_number)

    URL = URL_CURRENT
    URL_HOURLY = 'http://www.accuweather.com/%s/%s/hourly-weather-forecast/%s'%(weather_lang, city_id, city_number)
    URL_DAILY = 'http://www.accuweather.com/%s/%s/daily-weather-forecast/%s?day='%(weather_lang, city_id, city_number)

    print ('\033[34m>\033[0m '+_('Getting weather for')+' '+str(n)+' '+_('days'))

    source = urlopener(URL_CURRENT, 5)
    if not source:
        return False
    # time.sleep(1)

    # sun/moon
    sun_moon = re.findall('<span>(.*)</span></li>', source)

    if sun_moon:
        sunrise = sun_moon[1]
        sunset = sun_moon[2]
        sun_duration = sun_moon[3][:-3]
        moonrise = sun_moon[4]
        moonset = sun_moon[5]
        moon_duration = sun_moon[6][:-3]

    #### current weather ####
    # city
    city_name = re.findall('"current-city"><h1>(.*),', source)

    celsius = re.findall('\d\&deg;C', source)

    # temperature
    w_now = re.findall('detail-now.*', source, re.DOTALL)
    t_now = re.findall('<span class="large-temp">(.?\d+)', w_now[0])
    t_now_f = re.findall('<em>RealFeel&#174;</em>\s?(.?\d+)', w_now[0])
    if not celsius:
        t_now[0] = F_to_C(t_now[0])
        t_now_f[0] = F_to_C(t_now_f[0])
    t_now[0] = convert_from_C(t_now[0], t_now_f[0])

    # wind
    wind_speed_now = re.findall('<li class="wind"><strong>(\d*)', source)
    if wind_speed_now:
        wind_speed_now[0] = convert_from_kmh(wind_speed_now[0])
    wind_direct_now = re.findall('<div class="wind-point (.*)"', w_now[0])

    # icon
    icon_now = re.findall('<div class="icon (.*)xl"', w_now[0])
    icon_now[0] = convert(icon_now[0], icons_name)

    # wind icon
    icon_wind_now = ['']
    try:
        icon_wind_now[0] = wind_degree(wind_direct_now[0])
    except:
        icon_wind_now[0] = 'None'
    try:
        if wind_direct_now[0]=='CLM':
            wind_direct_now[0]=_('Calm')
        else:
            a=''
            for i in range(len(wind_direct_now[0])):
                a=a+_(wind_direct_now[0][i])
            wind_direct_now[0]=a
    except:
        wind_direct_now = []

    # weather text now
    text_now = re.findall('<span class="cond">(.*)<', w_now[0])
    text_now[0]=text_now[0].split('<')[0]
    
    # if show_block_add_info:
    source = urlopener(URL_ADD_INFO, 5)
    if not source:
        return False
    # time.sleep(1)

    # pressure now
    press = re.findall('Pressure.*>(.+?)<', source)
    if press:
        press_now = [press[0].split()[0]]
        press_scale = press[0].split()[1]
        if press_scale == 'mb':
            press_now[0] = convert_from_hPa(press_now[0])
        if press_scale == 'in':
            press_now[0] = convert_from_inHg(press_now[0])
    else:
        press_now = ['n/a mmHg;n/a inHg;n/a hPa']
    # humidity now
    hum_now = re.findall('Humidity.*>(\d+)', source)
    if not hum_now:
        hum_now=['n/a']

    #### weather to several days ####
    source = urlopener(URL_SEVERAL_DAYS, 5)
    if not source:
        return False

    # all days
    w_all = re.findall('<tr class="today lo calendar.*</table>', source, re.DOTALL)

    # day temperature
    t_day = re.findall('<td>(.*)&#176;/', w_all[0])
    t_day = t_day[::2]
    for i in range(len(t_day)):
        if not celsius:
            t_day[i] = F_to_C(t_day[i])
        t_day[i] = convert_from_C(t_day[i])

    # night temperature
    t_night = re.findall('<td>.*/(.*)&#176;', w_all[0])
    t_night = t_night[::2]
    for i in range(len(t_night)):
        if not celsius:
            t_night[i] = F_to_C(t_night[i])
        t_night[i] = convert_from_C(t_night[i])


    # day of week, date
    day = re.findall('<a.*>(.*)[.| ]*<time>', w_all[0])
    date = re.findall('<time>(.*)</time>', w_all[0])
    # try:
    #     int(date[0][:4])
    #     for i in range(len(date)):
    #         date[i]=date[i][5:]
    # except:
    #     for i in range(len(date)):
    #         date[i]=date[i][:-5]

    # weather icon day
    icon = re.findall('<div class="icon (.*)s"', w_all[0])
    for i in range(len(icon)):
        icon[i] = convert(icon[i], icons_name)


    # weather text
    text = re.findall('<p>(.*)</p>', w_all[0])

    chance_of_rain = re.findall('<td>(.*?)\s*<span class="small">(.*?)<', w_all[0])
    for i in range(len(chance_of_rain)):
        chance_of_rain[i] = ' '.join(chance_of_rain[i])
    chance_of_rain = chance_of_rain[::2]


    # if end of month, get days from next month
    if len(t_day)-1<n:
        try:
            next_month = re.findall('href="(.*)&amp;.*next-month', source)
            next_month[0] = next_month[0]+'&view=table'
            source = urlopener(next_month[0], 5)
            if not source:
                return False

            # all days
            w_all = re.findall('<tr class="lo calendar-list-cl-tr.*</table>', source, re.DOTALL)

            # day temperature
            t_day2 = re.findall('<td>(.*)&#176;/', w_all[0])
            t_day2 = t_day2[::2]
            for i in range(len(t_day2)):
                if not celsius:
                    t_day2[i] = F_to_C(t_day2[i])
                t_day2[i] = convert_from_C(t_day2[i])
            t_day.extend(t_day2)

            # night temperature
            t_night2 = re.findall('<td>.*/(.*)&#176;', w_all[0])
            t_night2 = t_night2[::2]
            for i in range(len(t_night2)):
                if not celsius:
                    t_night2[i] = F_to_C(t_night2[i])
                t_night2[i] = convert_from_C(t_night2[i])
            t_night.extend(t_night2)


            # day of week, date
            day2 = re.findall('<a.*>(.*)[.| ]*<time>', w_all[0])
            date2 = re.findall('<time>(.*)</time>', w_all[0])
            # try:
            #     int(date2[0][:4])
            #     for i in range(len(date2)):
            #         date2[i]=date2[i][5:]
            # except:
            #     for i in range(len(date2)):
            #         date2[i]=date2[i][:-5]
            day.extend(day2)
            date.extend(date2)


            # weather icon day
            icon2 = re.findall('<div class="icon (.*)s"', w_all[0])
            for i in range(len(icon2)):
                icon2[i] = convert(icon2[i], icons_name)
            icon.extend(icon2)


            # weather text
            text2 = re.findall('<p>(.*)</p>', w_all[0])
            # if text[-1] == '': # Need or not?
            #     del text[-1]
            text.extend(text2)


            chance_of_rain2 = re.findall('<td>(\d+)\s*<span class="small">(.*)</td>', w_all[0])
            for i in range(len(chance_of_rain2)):
                chance_of_rain2[i] = ' '.join(chance_of_rain2[i])
            if chance_of_rain2[1][-1] == '>':
                chance_of_rain2 = chance_of_rain2[::2]
            chance_of_rain.extend(chance_of_rain2)

        except:
            print('Can\'t get weather for next month')
            pass

    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])
            t_feel = re.findall('<em>RealFeel&#174;</em>\s?(.?\d+).*;/(.?\d+)', w_now[0])
            t_f = ['', '']
            if not celsius:
                t[0] = F_to_C(t[0])
                t_f[0] = F_to_C(t_feel[0][0])
                t_f[1] = F_to_C(t_feel[0][1])
            t[0] = convert_from_C(t[0], t_f[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_f[1])
            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_today:
        #### weather today ####
        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=1'%(city_id, w_time, city_number), 5)
            if not source[i]:
                return False

        t_today=[]
        t_today_low = []
        icon_today = []
        
        for s in source:
            w_now = re.findall('detail-now.*', s, re.DOTALL)
            
            t = re.findall('<span class="large-temp">(.?\d+)', w_now[0])
            t_feel = re.findall('<em>RealFeel&#174;</em>\s?(.?\d+).*;/(.?\d+)', w_now[0])
            t_f = ['', '']
            if not celsius:
                t[0] = F_to_C(t[0])
                t_f[0] = F_to_C(t_feel[0][0])
                t_f[1] = F_to_C(t_feel[0][1])
            t[0] = convert_from_C(t[0], t_f[0])
            t_today.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_f[1])
            t_today_low.append(t[0])
            
            i = re.findall('<div class="icon (.*)xl"', w_now[0])
            i[0] = convert(i[0], icons_name)
            icon_today.append(i[0])


    if time_update:
        print ('\033[34m>\033[0m '+_('updated on server')+' '+time_update[0]) 
    print ('\033[34m>\033[0m '+_('weather received')+' '+time.strftime('%H:%M', time.localtime()))

    # write variables
    for i in w.keys():
        w[i] = globals()[i]
    return w
Beispiel #2
0
def get_weather():
    global w, city_name, t_now, wind_speed_now, wind_direct_now, icon_now, icon_wind_now, time_update, text_now, press_now, hum_now, t_water_now, t_night, t_night_feel, day, date, t_day, t_day_feel, icon, icon_wind, wind_speed, wind_direct, text, t_tomorrow, t_tomorrow_feel, icon_tomorrow, wind_speed_tom, wind_direct_tom, t_today, t_today_feel, icon_today, wind_speed_tod, wind_direct_tod, chance_of_rain, t_today_low, t_tomorrow_low
    n = gw_vars.get('n')
    city_id = gw_vars.get('city_id')
    show_block_tomorrow = gw_vars.get('show_block_tomorrow')
    show_block_today = gw_vars.get('show_block_today')
    show_block_add_info = gw_vars.get('show_block_add_info')
    weather_lang = gw_vars.get('weather_lang')
    icons_name = gw_vars.get('icons_name')
    if city_id.split(',')[0]==city_id.split(',')[-1]:
        city_number = city_id.split('/')[-1]
    else:
        city_number = city_id.split(',')[-1].strip()
        city_id = city_id.split(',')[0].strip()
    URL_CURRENT = 'http://www.accuweather.com/%s/%s/current-weather/%s'%(weather_lang, city_id, city_number)
    URL_ADD_INFO = 'http://www.accuweather.com/en/%s/current-weather/%s'%(city_id, city_number)
    URL_SEVERAL_DAYS = 'http://www.accuweather.com/%s/%s/month/%s?view=table'%(weather_lang, city_id, city_number)

    print ('\033[34m>\033[0m '+_('Getting weather for')+' '+str(n)+' '+_('days'))

    source = urlopener(URL_CURRENT, 5)
    if not source:
        return False
    #### current weather ####
    # city
    city_name = re.findall('"current-city"><h1>(.*),', source)

    celsius = re.findall('celsius.*checked', source)

    # temperature
    t_now = re.findall('<span class="temp">(.?\d+)<', source)
    if not celsius:
        t_now[0] = F_to_C(t_now[0])
    # if t_now[0][0] not in ('+', '-', '0'):
    #         t_now[0] = '+'+t_now[0]
    t_now[0] = convert_from_C(t_now[0])

    # wind
    wind_speed_now = re.findall("<div style=\".+\">(\d*).*</div>", source)
    if wind_speed_now:
        wind_speed_now[0] = convert_from_kmh(wind_speed_now[0])
    wind_direct_now = re.findall("arrow-lg-(.*)\.png", source)

    # icon
    icon_now = re.findall('<div class="forecast">\s*<div class="icon (.*)"></div>', source)
    icon_now[0] = icon_now[0][2:]
    if len(icon_now[0])==4:
        icon_now[0]='0'+icon_now[0]
    icon_now[0] = 'http://vortex.accuweather.com/adc2010/images/icons-numbered/'+icon_now[0]+'.png'
    icon_now[0] = convert(icon_now[0], icons_name)
    
    # wind icon
    icon_wind_now = ['']
    try:
        icon_wind_now[0] = wind_degree(wind_direct_now[0])
    except:
        icon_wind_now[0] = 'None'
    try:
        if wind_direct_now[0]=='CLM':
            wind_direct_now[0]=_('Calm')
        else:
            a=''
            for i in range(len(wind_direct_now[0])):
                a=a+_(wind_direct_now[0][i])
            wind_direct_now[0]=a
    except:
        wind_direct_now = []

    
    # weather text now
    text_now = re.findall('<div class="info"> <span class="cond">(.*)<', source)
    text_now[0]=text_now[0].split('<')[0]

    if show_block_add_info:
        source = urlopener(URL_ADD_INFO, 5)
        if not source:
            return False

        # pressure now
        press_now = re.findall('Pressure.*>(\d+)', source)
        try:
            press_now[0] = str(round(int(press_now[0])*0.75))+' mmHg;'+str(round(int(press_now[0])*0.0295))+' inHg;'+press_now[0]+' hPa'
        except:
            press_now = ['n/a mmHg;n/a inHg;n/a hPa']
        # humidity now
        hum_now = re.findall('Humidity.*>(\d+)', source)
        if not hum_now:
            hum_now=['n/a']

    #### weather to several days ####
    source = urlopener(URL_SEVERAL_DAYS, 5)
    if not source:
        return False

    # all days
    w_all = re.findall('<tr class="lo calendar.*</table>', source, re.DOTALL)

    # day temperature
    t_day = re.findall('<td style="font-weight:bold;">(.*)&#176;', w_all[0])
    for i in range(len(t_day)):
        # if t_day[i][0] not in ('+', '-', '0'):
        #     t_day[i] = '+' + t_day[i]
        if not celsius:
            t_day[i] = F_to_C(t_day[i])
        t_day[i] = convert_from_C(t_day[i])

    # night temperature
    t_night = re.findall('<td style="font-weight:bold;">.*\s*<td>(.*)&#176;', w_all[0])
    for i in range(len(t_night)):
        # if t_night[i][0] not in ('+', '-', '0'):
        #     t_night[i] = '+' + t_night[i]
        if not celsius:
            t_night[i] = F_to_C(t_night[i])
        t_night[i] = convert_from_C(t_night[i])


    # day of week, date
    day = re.findall('color:.*>(.*)<br', w_all[0])
    date = re.findall('<br />([\d|.\-/]+)<', w_all[0])
    try:
        int(date[0][:4])
        for i in range(len(date)):
            date[i]=date[i][5:]
    except:    
        for i in range(len(date)):
            date[i]=date[i][:-5]

    # weather icon day
    icon = re.findall('src=\"(.*png)\" ', w_all[0])
    for i in range(len(icon)):
        icon[i] = convert(icon[i], icons_name)


    # weather text
    text = re.findall('src=.*>(.*)\r', w_all[0])

    chance_of_rain = re.findall('<td style="font-weight:bold;">.*\s*<td>.*\s*<td>(.*)<', w_all[0])
    # if end of month, get days from next month
    if len(t_day)-1<n:
        try:
            next_month = re.findall('href="(.*)&amp;view=table".*next-month"', source)
            next_month[0] = next_month[0]+'&view=table'
            source = urlopener(next_month[0], 5)
            if not source:
                return False

            # all days
            w_all = re.findall('<tr class="lo calendar.*</table>', source, re.DOTALL)

            # day temperature
            t_day2 = re.findall('<td style="font-weight:bold;">(.*)&#176;', w_all[0])
            for i in range(len(t_day2)):
                if t_day2[i][0] not in ('+', '-', '0'):
                    t_day2[i] = '+' + t_day2[i]
                if not celsius:
                    t_day2[i] = F_to_C(t_day2[i])
                t_day2[i] = t_day2[i]+'°;'+t_day2[i]+'°;'+C_to_F(t_day2[i])+'°;'+C_to_F(t_day2[i])+'°;'+C_to_K(t_day2[i])+';'+C_to_K(t_day2[i]) 
            t_day.extend(t_day2)

            # night temperature
            t_night2 = re.findall('<td style="font-weight:bold;">.*\s*<td>(.*)&#176;', w_all[0])
            for i in range(len(t_night2)):
                if t_night2[i][0] not in ('+', '-', '0'):
                    t_night2[i] = '+' + t_night2[i]
                if not celsius:
                    t_night2[i] = F_to_C(t_night2[i])
                t_night2[i] = t_night2[i]+'°;'+t_night2[i]+'°;'+C_to_F(t_night2[i])+'°;'+C_to_F(t_night2[i])+'°;'+C_to_K(t_night2[i])+';'+C_to_K(t_night2[i])
            t_night.extend(t_night2)

            # day of week, date
            day2 = re.findall('color:.*>(.*)<br', w_all[0])
            date2 = re.findall('<br />([\d|.\-/]+)<', w_all[0])
            try:
                int(date2[0][:4])
                for i in range(len(date2)):
                    date2[i]=date2[i][5:]
            except:    
                for i in range(len(date2)):
                    date2[i]=date2[i][:-5]
            day.extend(day2)
            date.extend(date2)
            # weather icon day
            icon2 = re.findall('src=\"(.*png)\" ', w_all[0])
            for i in range(len(icon2)):
                icon2[i] = convert(icon2[i], icons_name)
            icon.extend(icon2)

            # weather text
            text2 = re.findall('src=.*>(.*)\r', w_all[0])
            if text[-1] == '':
                del text[-1]
            chance_of_rain2 = re.findall('<td style="font-weight:bold;">.*\s*<td>.*\s*<td>(.*)<', w_all[0])
            text.extend(text2)
            chance_of_rain.extend(chance_of_rain2)
        except:
            pass

    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

        w_morning = urlopener('http://www.accuweather.com/en/%s/morning-weather-forecast/%s?day=2'%(city_id, city_number))
        if not w_morning:
            return False

        w_day = urlopener('http://www.accuweather.com/en/%s/afternoon-weather-forecast/%s?day=2'%(city_id, city_number))
        if not w_day:
            return False
        
        w_evening = urlopener('http://www.accuweather.com/en/%s/evening-weather-forecast/%s?day=2'%(city_id, city_number))
        if not w_evening:
            return False
        
        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])

        
    if show_block_today:
        #### weather today ####
        w_night = urlopener('http://www.accuweather.com/en/%s/overnight-weather-forecast/%s?day=1'%(city_id, city_number), 5)
        if not w_night:
            return False

        w_morning = urlopener('http://www.accuweather.com/en/%s/morning-weather-forecast/%s?day=1'%(city_id, city_number))
        if not w_morning:
            return False

        w_day = urlopener('http://www.accuweather.com/en/%s/afternoon-weather-forecast/%s?day=1'%(city_id, city_number))
        if not w_day:
            return False
        
        w_evening = urlopener('http://www.accuweather.com/en/%s/evening-weather-forecast/%s?day=1'%(city_id, city_number))
        if not w_evening:
            return False
        
        t_today=[]

        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_today.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_today.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_today.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_today.append(t[0])


        t_today_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_today_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_today_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_today_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_today_low.append(t[0])

        
        icon_today=[]

        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_today.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_today.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_today.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_today.append(i[0])

    
    if time_update:
        print ('\033[34m>\033[0m '+_('updated on server')+' '+time_update[0]) 
    print ('\033[34m>\033[0m '+_('weather received')+' '+time.strftime('%H:%M', time.localtime()))

    # write variables
    for i in w.keys():
        w[i] = globals()[i]
    return w