magtag.add_text( text_position=(70, 30), text_font="/fonts/Arial-12.bdf", text_transform=lambda x: "@%s" % x, ) # Tweet text magtag.add_text( text_font="/fonts/Arial-Bold-12.pcf", text_wrap=30, text_maxlen=160, text_position=( 5, (magtag.graphics.display.height // 2) + 20, ), line_spacing=0.75, ) # preload characters magtag.preload_font() try: value = magtag.fetch() print("Response is", value) except (ValueError, RuntimeError) as e: print("Some error occured, retrying! -", e) time.sleep(2) print("Sleeping!") magtag.exit_and_deep_sleep(SLEEP_TIME * 60)
magtag.add_text(text_position=(5, 30), text_scale=2) magtag.add_text(text_position=(10, 50), text_transform=lambda x: "Current: {}F".format(x), text_scale=2) magtag.add_text(text_position=(10, 75), text_transform=lambda x: "Max: {}F".format(x), text_scale=2) magtag.add_text(text_position=(120, 75), text_transform=lambda x: "Min: {}F".format(x), text_scale=2) magtag.add_text(text_position=(10, 110), text_scale=2) magtag.add_text(text_position=(130, 110), text_transform=lambda x: "{} mph".format(x), text_scale=2) magtag.peripherals.neopixels.brightness = 0.1 magtag.peripherals.neopixels.disable = False magtag.peripherals.neopixels.fill(0x0F0000) raw = magtag.fetch() print(raw) magtag.exit_and_deep_sleep(900)
# Des Moines Info add_text(140, 10) magtag.set_text('Des Moines County', 4, False) add_text(145, 40) add_text(145, 55) add_text(145, 70) add_text(145, 85) add_text(145, 100) magtag.peripherals.neopixels.brightness = 0.1 magtag.peripherals.neopixels.disable = False magtag.peripherals.neopixels.fill(0x0F0000) magtag.get_local_time() value = magtag.fetch(HOSPITAL_DATA) # print('Response is', value) json_value = json.loads(value) data = json_value["features"][0]["attributes"] magtag.set_text(format_date_time(data["last_updated"] / 1000), 1, False) magtag.set_text("Hospitalized: {}".format(data["CurrHospitalized"]), 2, False) magtag.set_text("Total Dead: {}".format(data["Deceased"]), 3, False) value = magtag.fetch(DM_COUNTY_DATA) json_value = json.loads(value) data = json_value["features"][0]["attributes"] magtag.set_text(format_date_time(data["last_updated"] / 1000), 5, False) magtag.set_text("Total Cases: {}".format(data["Confirmed"]), 6, False) magtag.set_text("Tested: {}%".format(format_percent(data["individuals_tested"], data["pop_est_2018"])), 7, False) magtag.set_text("Infected: {}%".format(format_percent(data["Confirmed"], data["pop_est_2018"])), 8, False) magtag.set_text("Deaths: {}".format(data["Deaths"]), 9, False)
line_list = [] print(line) while "," in line: if line[0] == '"': temp = line.split('"', 2)[1] line_list.append(temp) line = line.split('"', 2)[2][1:] else: temp, line = line.split(",", 1) line_list.append(temp) line_list.append(line) return line_list try: table = magtag.fetch().split("\n") columns = l_split(table[0]) latest = l_split(table[-2]) print(columns) print(latest) value = dict(zip(columns, latest)) print("Response is", value) print(value) vaccinated = int(value["people_vaccinated"]) / 331984513 fully_vaccinated = int(value["people_fully_vaccinated"]) / 331984513 magtag.set_text(f"{value['location']} Vaccination Rates", 0, False) magtag.set_text(value["date"], 1, False) magtag.set_text("Vaccinated: {:.2f}%".format(vaccinated * 100), 2, False) magtag.set_text("Fully Vaccinated: {:.2f}%".format(fully_vaccinated * 100),
# datestamp magtag.add_text( text_scale=2, text_position=(10, 65), text_transform=lambda x: "Updated on:\n{}".format(x), # pylint: disable=unnecessary-lambda ) timestamp = None while True: if not timestamp or ((time.monotonic() - timestamp) > refresh_rate): # Refresh rate in seconds try: # Turn on the MagTag NeoPixels. magtag.peripherals.neopixel_disable = False # Fetch the color and datetime, and print it to the serial console. cheerlights_update_info = magtag.fetch() print("Response is", cheerlights_update_info) # Get the color from the fetched info for use below. cheerlights_color = cheerlights_update_info[0] # If red, blue or pink, do a comet animation in the specified color. if cheerlights_color in ('red', 'blue', 'pink'): if cheerlights_color == 'red': comet_color = RED elif cheerlights_color == 'blue': comet_color = BLUE elif cheerlights_color == 'pink': comet_color = PINK animations = AnimationSequence( AnimationGroup(
outline_color=0x000000) progress_bar_1 = ProgressBar(BAR_X, 95, BAR_WIDTH, BAR_HEIGHT, 1.0, bar_color=0x999999, outline_color=0x000000) magtag.graphics.splash.append(progress_bar) magtag.graphics.splash.append(progress_bar_1) magtag.graphics.set_background("/bmps/background.bmp") try: value = magtag.fetch().split("\n")[-2].split(",") print("Response is", value) vaccinated = int(value[-2]) / 331984513 fully_vaccinated = int(value[-1]) / 331984513 magtag.set_text(f"{value[0]} Vaccination Rates", 0, False) magtag.set_text(value[1], 1, False) magtag.set_text("Vaccinated: {:.2f}%".format(vaccinated * 100), 2, False) magtag.set_text("Fully Vaccinated: {:.2f}%".format(fully_vaccinated * 100), 3, False) progress_bar.progress = vaccinated progress_bar_1.progress = fully_vaccinated magtag.refresh()