print('Updating produce') PRODUCE.fetch(MAGTAG) # Set the "Updated" date and time label if DD_MM: DATE = '%d/%d' % (NOW.tm_mday, NOW.tm_mon) else: DATE = '%d/%d' % (NOW.tm_mon, NOW.tm_mday) MAGTAG.set_text('Updated %s %s' % (DATE, hh_mm(NOW, TWELVE_HOUR)), 1, auto_refresh=False) # Look up the matching produce data (returned as list of strings) PRODUCE_LIST = PRODUCE.in_season(NOW.tm_mon) NUM_ITEMS = len(PRODUCE_LIST) print('Produce list: ', PRODUCE_LIST) # List one item per line since some may be long VEGGIE_LIST = '' for item in PRODUCE_LIST: VEGGIE_LIST += '\n'.join(MAGTAG.wrap_nicely(item, 15)) + '\n' MAGTAG.set_text(VEGGIE_LIST) # Update list on the display time.sleep(2) # Allow refresh to finish before deep sleep print('Zzzz time') MAGTAG.exit_and_deep_sleep(24 * 60 * 60) # 24 hour snooze except RuntimeError as error: # If there's an error above, no harm, just try again in ~15 minutes. # Usually it's a common network issue or time server hiccup. print('Retrying in 15 min - ', error) MAGTAG.exit_and_deep_sleep(15 * 60) # 15 minute snooze
), line_spacing=0.85, text_anchor_point=(0.5, 0.5), ) # Set up buttons cur_btn = False prev_btn = False while True: # Shuffle the deck cards = sorted(cards, key=lambda _: random.random()) for card in cards: # Show the first side and wait for the D button text = ''.join(magtag.wrap_nicely(card[0], 20)) magtag.set_text(text) while True: cur_btn = magtag.peripherals.button_d_pressed if cur_btn and not prev_btn: print("Show Result") time.sleep(0.1) break prev_btn = cur_btn # Show the second side and wait for the D button text = '\n'.join(magtag.wrap_nicely(card[1], 11)) text += '\n' text += '\n'.join(magtag.wrap_nicely(card[2], 20)) print(text) magtag.set_text(text)