def fetchDate(wrds): word_idx = None ### alarm.sleep_memory isn't present on PyPortal ### Storing the word_idx in a register on the temperature sensor - niishhh! import adafruit_adt7410 adafruit_adt7410.ADT7410.reset = lambda self: self ### nobble the reset adt = adafruit_adt7410.ADT7410(board.I2C(), address=0x48) ### Look for a value (well) below default of 10 degrees if adt.low_temperature < 0.0: word_idx = round((0.0 - adt.low_temperature) * 128) wrds.selector_value = word_idx d_print(1, "Retrieved word_idx", word_idx) ### If word_idx isn't set need to fetch the data from t'Internet if word_idx is None: import supervisor import adafruit_datetime from adafruit_pyportal import PyPortal pyportal = PyPortal(status_neopixel=board.NEOPIXEL) pyportal.get_local_time() wordle_oday = adafruit_datetime.date(*wrds.selector_value).toordinal() now_oday = adafruit_datetime.datetime.now().toordinal() word_idx = now_oday - wordle_oday d_print(1, "Saving word_idx", word_idx) adt.low_temperature = (0 - word_idx ) / 128 time.sleep(10) supervisor.reload()
status_neopixel=board.NEOPIXEL, default_bg=0x000000) gfx = openweather_graphics.OpenWeather_Graphics(pyportal.splash, am_pm=True, celsius=False) localtile_refresh = None weather_refresh = None while True: # only query the online time once per hour (and on first run) if (not localtile_refresh) or (time.monotonic() - localtile_refresh) > 3600: try: print("Getting time from internet!") pyportal.get_local_time() localtile_refresh = time.monotonic() except RuntimeError as e: print("Some error occured, retrying! -", e) continue # only query the weather every 10 minutes (and on first run) if (not weather_refresh) or (time.monotonic() - weather_refresh) > 600: try: value = pyportal.fetch() print("Response is", value) gfx.display_weather(value) weather_refresh = time.monotonic() except RuntimeError as e: print("Some error occured, retrying! -", e) continue
label_month.y = 80 pyportal.splash.append(label_month) # Set up label for the time label_time = label.Label(font_small, color=LABEL_TIME_COLOR, max_glyphs=200) label_time.x = board.DISPLAY.width // 3 label_time.y = 150 pyportal.splash.append(label_time) refresh_time = None while True: # only query the network time every hour if (not refresh_time) or (time.monotonic() - refresh_time) > 3600: try: print("Getting new time from internet...") pyportal.get_local_time(secrets['timezone']) refresh_time = time.monotonic() # set the_time the_time = time.localtime() except (ValueError, RuntimeError) as e: print("Failed to get data, retrying\n", e) esp.reset() continue # convert tm_mon value to month name month = months[the_time.tm_mon] # determine and display how far we are in the month if 1 <= the_time.tm_mday <= 14: label_month.text = "Early %s-ish" % month elif 15 <= the_time.tm_mday <= 24:
caption_color=0x000000) countdown_text = Label(big_font, max_glyphs=3) countdown_text.x = 25 countdown_text.y = 120 countdown_text.color = 0x7942a0 pyportal.splash.append(countdown_text) refresh_time = None while True: # only query the online time once per hour (and on first run) if (not refresh_time) or (time.monotonic() - refresh_time) > 3600: try: print("Getting time from internet!") pyportal.get_local_time(location=secrets['timezone']) refresh_time = time.monotonic() except RuntimeError as e: print("Some error occured, retrying! -", e) continue timestamp = time.localtime() now = time.struct_time(( timestamp[0], timestamp[1], timestamp[2], 0, 0, 0, # we don't track seconds -1, -1,
text_areas = [] for pos in (days_position, hours_position, minutes_position): textarea = Label(big_font, text=' ') textarea.x = pos[0] textarea.y = pos[1] textarea.color = text_color pyportal.splash.append(textarea) text_areas.append(textarea) refresh_time = None while True: # only query the online time once per hour (and on first run) if (not refresh_time) or (time.monotonic() - refresh_time) > 3600: try: print("Getting time from internet!") pyportal.get_local_time(location=EVENT_LOCATION) refresh_time = time.monotonic() except RuntimeError as e: print("Some error occured, retrying! -", e) continue the_time = time.localtime() print("Time at location", EVENT_LOCATION, ":", the_time) # The easiest way to tell when mins_remaining = EVENT_MINUTE - the_time[4] if mins_remaining < 0: mins_remaining += 60 # add minutes to go forward the_time = time.localtime(time.mktime(the_time) + mins_remaining * 60) #print("minute fastforward:", the_time)
(140, 160)), # Direction location text_color=( 0x000000, # BG text color 0x000000), # Direction text color text_wrap=( 35, # characters to wrap for BG 0), # no wrap for direction text_maxlen=(180, 30), # max text size for BG & direction text_transform=(text_transform_bg, text_transform_direction ), # pre-processing of the text to ensure proper format ) # Preload the font for performance pyportal.preload_font(b'mg/dl012345789') pyportal.preload_font((0x2191, 0x2192, 0x2193)) # # main loop # while True: try: value = pyportal.fetch() print("Getting time from internet!") pyportal.get_local_time(location="Africa/Abidjan") pyportal.set_background(get_bg_color(value[0], value[2])) print("Response is", value) except RuntimeError as e: print("Some error occured, retrying! -", e) time.sleep(180)
0x000000, # BG text color 0x000000, 0x000000), # Direction text color text_wrap=( 35, # characters to wrap for BG 0, 0), # no wrap for direction text_maxlen=(180, 30, 100), # max text size for BG & direction text_transform=( text_transform_bg, text_transform_direction, data_age), # pre-processing of the text to ensure proper format ) # Preload the font for performance pyportal.preload_font(b'mg/dl012345789') pyportal.preload_font((0x2191, 0x2192, 0x2193, 0x2197, 0x2198, 0x21d1, 0x21d3)) # # main loop # while True: try: value = pyportal.fetch() print("Getting time from internet!") pyportal.get_local_time(location=secrets["timezone"]) pyportal.set_background(get_bg_color(value[0])) print("Response is", value) except RuntimeError as e: print("Some error occured, retrying! -", e) time.sleep(180)