Exemple #1
0
def update():
    """
    Init
    """
    global APIKEY
    global TIMEOUT
    global font
    global TEMP_FILE
    global screen
    global lcd
    global icons
    global cur_location
    global fio

    #lcd.clear()
    """
    Main Code
    """
    try:
        with timeout.timeout(seconds=TIMEOUT):
            fio.get_forecast(cur_location[0], cur_location[1])
    except:
        retry_attempt()

    fiocur = FIOCurrently.FIOCurrently(fio)
    current = fiocur.get()
    temp = weather.get_temperature(current)
    icon = icons[weather.get_icon(current)]
    chance_of_rain = weather.get_rain_chance(fio)
    print((temp, weather.get_icon(current)))
    #lcd.clear()
    """
Exemple #2
0
def first_start():

    global TIMEOUT
    global icons
    global screen
    global lcd
    global cur_location
    global fio

    wake()
    not_connected = True

    try:
        time_start = time.time()
        images.display_img(icons["weatherdash_logo"], screen, lcd, 60, 20, 10)
        lcd.pos(6, 40)
        lcd.puts("Loading...")
        while not_connected:
            try:
                with timeout.timeout(seconds=2):
                    fio.get_forecast(cur_location[0], cur_location[1])
                    not_connected = False
            except:
                time_elapsed = time.time() - time_start
                if time_elapsed > 300:
                    raise timeout.TimeoutError("Max Timeout")
                else:
                    time.sleep(2)
                    continue
    except timeout.TimeoutError:
        retry_attempt()
    screen.clear()
    lcd.clear()
    update()
Exemple #3
0
def first_start():

    global TIMEOUT
    global icons
    global screen
    global lcd
    global cur_location
    global fio
    global TIMEZONES
    global TIMEZONE
    global cur_time

    wake()
    load_count = 0

    images.display_img(icons["weatherdash_logo"], screen, lcd, 60, 20, 10)
    not_connected = True

    try:
        time_start = time.time()
        while not_connected:
            try:
                with timeout.timeout(seconds=2):
                    lcd.pos(6, 40)
                    if load_count == 0 or load_count >= 4:
                        lcd.puts("Loading   ")
                        load_count = 0
                    elif load_count == 1:
                        lcd.puts("Loading.  ")
                    elif load_count == 2:
                        lcd.puts("Loading.. ")
                    elif load_count == 3:
                        lcd.puts("Loading... ")
                    load_count += 1

                    fio.get_forecast(cur_location[0], cur_location[1])
                    not_connected = False
            except:
                time_elapsed = time.time() - time_start
                if time_elapsed > 300:
                    raise timeout.TimeoutError("Max Timeout")
                else:
                    time.sleep(2)
                    continue
    except timeout.TimeoutError:
        retry_attempt()
    screen.clear()
    lcd.clear()
    cur_time = str(datetime.now().time())
    cur_time = int(cur_time[0:2])
    cur_time -= TIMEZONES[TIMEZONE]

    if cur_time < 0:
        cur_time += 24
    if cur_time < 7 or cur_time >= 23:
        sleep()
    else:
        update()
Exemple #4
0
def retry_attempt():
    global TIMEOUT
    global lcd
    global cur_location
    global fio

    time_start = time.time()
    retry_timeout = TIMEOUT * 2
    not_connected = True
    print("Error")
    """
    lcd.clear()
    lcd.puts("Error") 
    lcd.pos(1)
    lcd.puts("Unable to update data")
    lcd.pos(2)
    lcd.puts("Check your Internet Connection")
    """
    time.sleep(1)
    i = 10
    while (i > 0):
        """
        text = "Retrying in " + "  " + " seconds..."
        lcd.pos(3)
        lcd.puts(text)
        text = "Retrying in " + str(i) + " seconds..."
        lcd.pos(3)
        lcd.puts(text)
        """
        time.sleep(1)
        i -= 1
    try:

        while not_connected:
            try:
                with timeout.timeout(seconds=retry_timeout):
                    fio.get_forecast(cur_location[0], cur_location[1])
                    not_connected = False
            except:
                time_elapsed = time.time() - time_start
                if time_elapsed > retry_timeout:
                    raise timeout.TimeoutError("Max Timeout")
                else:
                    time.sleep(2)
                    continue
    except timeout.TimeoutError:
        """
        lcd.pos(4)
        lcd.puts("Failed.")
        lcd.pos(5)
        lcd.puts("Rebooting device in 5s")
        """
        time.sleep(5)
        reboot()
Exemple #5
0
def update():
    """
    Init
    """
    global APIKEY
    global TIMEOUT
    global font
    global TEMP_FILE
    global screen
    global lcd
    global icons
    global cur_location
    global fio
    global cur_time

    lcd.clear()
    """
    Main Code
    """
    try:
        with timeout.timeout(seconds=TIMEOUT):
            fio.get_forecast(cur_location[0], cur_location[1])
    except:
        retry_attempt()

    fiocur = FIOCurrently.FIOCurrently(fio)
    current = fiocur.get()
    temp = weather.get_temperature(current)
    icon = icons[weather.get_icon(current)]
    rain_time = ""

    if cur_time >= OVERVIEW_TIME:
        overview = 23
    else:
        overview = OVERVIEW_TIME

    hour_range = overview - cur_time

    if hour_range <= 0:
        hour_range = 1
    chance_of_rain, rain_hour = weather.get_rain_chance(fio, hour_range)
    rain_hour += cur_time
    if rain_hour > 23:
        rain_hour = 23
    if rain_hour <= 0:
        rain_time = "n"
    elif rain_hour > 12:
        rain_hour -= 12
        rain_time = str(rain_hour) + "a"
    elif rain_hour == 12:
        rain_time = "12a"
    else:
        rain_time = str(rain_hour) + "m"
    lcd.clear()

    screen = images.display_img(icon, screen, lcd, 70, 77)
    screen = fonts.display_s(str(temp) + "d", font, screen, lcd, 5, 5, 7)
    screen = images.display_img(icons["umbrella"], screen, lcd, 20, 40, 48)
    test_font = fonts.create_font("pixel", False)
    if chance_of_rain >= 0.0:
        screen = fonts.display_s(
            str(chance_of_rain) + "p", font, screen, lcd, 2, 57, 48)
        #screen = images.display_img(icons["at"], screen, lcd, 15, 69, 51)
        #screen = fonts.display_s(rain_time,font, screen, lcd, 1.5, 84, 51)
    temp = open(TEMP_FILE, "w")
    pickle.dump(screen, temp, -1)