def __init__(self, magtag: MagTag) -> None: self._magtag = magtag magtag.add_text( text_position=( 50, 10, ), text_scale=3, ) magtag.set_text("Spotlight")
# Filters out characters that the API or the MagTag itself isn't handling correctly for char in range(1, 32): selected["projectDescription"].replace(chr(char), "") selected["projectDescription"] = (selected["projectDescription"].replace( "'", "'").replace("'", "'").replace("/", "/").replace(""", '"').replace("’", "'")) # Add the two text fields magtag.add_text( text_font="fonts/Arial-Bold-12.bdf", text_position=(5, 0), text_scale=1, line_spacing=0.7, text_anchor_point=(0, 0), ) magtag.add_text( text_font="fonts/ArialMT-9.bdf", text_position=(5, 38), text_scale=1, line_spacing=0.6, text_anchor_point=(0, 0), ) # Create the QR code url = f"https://certification.oshwa.org/{selected['oshwaUid'].lower()}.html" magtag.graphics.qrcode(url, qr_size=4, x=173, y=3)
elif time_struct.tm_hour > 0: hour_string = str(time_struct.tm_hour) # 1-12 else: hour_string = '12' # 0 -> 12 (am) else: hour_string = '{hh:02d}'.format(hh=time_struct.tm_hour) return hour_string + ':{mm:02d}'.format(mm=time_struct.tm_min) # GRAPHICS INITIALIZATION -------------------------------------------------- # First text label (index 0) is day of week -- empty for now, is set later MAGTAG.add_text( text_font='/fonts/helvB24.pcf', text_position=(MAGTAG.graphics.display.width // 2, 4), line_spacing=1.0, text_anchor_point=(0.5, 0), # Center top is_data=False, # Text will be set manually ) # Second (index 1) is task list -- again, empty on start, is set later MAGTAG.add_text( text_font='/fonts/ncenR14.pcf', text_position=(3, 36), line_spacing=1.0, text_anchor_point=(0, 0), # Top left is_data=False, # Text will be set manually ) # Add 14-pixel-tall black bar at bottom of display. It's a distinct layer # (not just background) to appear on top of task list if it runs long.
TIME_BETWEEN_REFRESHES = 1 * 60 * 60 # one hour delay magtag = MagTag( url=DATA_SOURCE, json_path=(QUOTE_LOCATION, AUTHOR_LOCATION), ) magtag.graphics.set_background("/bmps/magtag_quotes_bg.bmp") # quote in bold text, with text wrapping magtag.add_text( text_font="/fonts/Arial-Bold-12.bdf", text_wrap=28, text_maxlen=120, text_position=( (magtag.graphics.display.width // 2), (magtag.graphics.display.height // 2) - 10, ), line_spacing=0.75, text_anchor_point=(0.5, 0.5), # center the text on x & y ) # author in italic text, no wrapping magtag.add_text( text_font="/fonts/Arial-Italic-12.bdf", text_position=(magtag.graphics.display.width // 2, 118), text_anchor_point=(0.5, 0.5), # center it in the nice scrolly thing ) # OK now we're ready to connect to the network, fetch data and update screen! try:
return "%s %d, at %s" % (months[month - 1], day, timestring) def details_transform(val3): if val3 == None or not len(val3): return "Details: To Be Determined" return "Details: " + val3[0:166] + "..." # Set up the MagTag with the JSON data parameters magtag = MagTag(url=DATA_SOURCE, json_path=(NAME_LOCATION, DATE_LOCATION, DETAIL_LOCATION)) magtag.add_text(text_font="/fonts/Lato-Bold-ltd-25.bdf", text_position=(10, 15), is_data=False) # Display heading text below with formatting above magtag.set_text("Next SpaceX Launch") # Formatting for the mission text magtag.add_text(text_font="/fonts/Arial-Bold-12.pcf", text_position=(10, 38), text_transform=mission_transform) # Formatting for the launch time text magtag.add_text(text_font="/fonts/Arial-12.bdf", text_position=(10, 60), text_transform=time_transform) # Formatting for the details text
if config['mode'] is 'local': verses = json.loads(open("verses.json").read()) print("using local verses.") else: verses = webverse.json() print("using web verses") print('.......................................................') print(json.dumps(verses)) print('.......................................................') # main text large font, used to display script index 0 during dev. magtag.add_text( text_font=terminalio.FONT if PLAINFONT else "Arial-Bold-24.bdf", text_position=( magtag.graphics.display.width // 2, 10, ), text_scale=3 if PLAINFONT else 1, line_spacing=1, text_anchor_point=(0.5, 0), ) # verse text, index 1 magtag.add_text( text_font=terminalio.FONT if PLAINFONT else "Arial-12.bdf", text_position=(3, 5), line_spacing=.9, text_wrap=39, text_maxlen=202, text_anchor_point=(0, 0), )
) dose2_us_progress_bar = ProgressBar( US_BAR_X, DOSE2_BAR_Y, BAR_WIDTH, BAR_HEIGHT, 1.0, bar_color=0x999999, outline_color=0x000000, ) # name magtag.add_text( text_font="fonts/leaguespartan18.bdf", text_position=( (magtag.graphics.display.width // 2) - 1, 20, ), text_anchor_point=(0.5, 0.5), ) # NY Percent magtag.add_text( text_font="fonts/leaguespartan18.bdf", text_position=( (magtag.graphics.display.width // 4) - 1, 45, ), text_anchor_point=(0.5, 0.5), ) # US Percent
import time from adafruit_magtag.magtag import MagTag USE_AMPM_TIME = True weekdays = ("mon", "tue", "wed", "thur", "fri", "sat", "sun") last_sync = None last_minute = None magtag = MagTag() magtag.graphics.set_background("/background.bmp") mid_x = magtag.graphics.display.width // 2 - 1 magtag.add_text( text_font="Lato-Regular-74.bdf", text_position=(mid_x, 10), text_anchor_point=(0.5, 0), is_data=False, ) magtag.set_text("00:00a", auto_refresh=False) magtag.add_text( text_font="/BebasNeueRegular-41.bdf", text_position=(126, 86), #was 141 text_anchor_point=(0, 0), is_data=False, ) magtag.set_text("DAY 00:00a", index=1, auto_refresh=False) def hh_mm(time_struct, twelve_hour=True): """ Given a time.struct_time, return a string as H:MM or HH:MM, either
# Set up where we'll be fetching data from DATA_SOURCE = "http://api.thingspeak.com/channels/1417/field/2/last.json" COLOR_LOCATION = ['field2'] DATE_LOCATION = ['created_at'] magtag = MagTag( url=DATA_SOURCE, json_path=(COLOR_LOCATION, DATE_LOCATION), ) magtag.network.connect() # Color magtag.add_text( text_font="Arial-Bold-12.bdf", text_position=(10, 15), text_transform=lambda x: "New Color {}".format(x), ) # datestamp magtag.add_text( text_font="Arial-Bold-12.bdf", text_position=(10, 35), text_transform=lambda x: "Updated on: {}".format(x), ) timestamp = None while True: if not timestamp or ( (time.monotonic() - timestamp) > 10): # once every 10 seconds... try: value = magtag.fetch()
"https://raw.githubusercontent.com/codyogden/killedbygoogle/main/graveyard.json" ) # Get the MagTag ready MAGTAG = MagTag() MAGTAG.peripherals.neopixel_disable = True MAGTAG.set_background("/bmps/background.bmp") MAGTAG.network.connect() # Prepare the three text fields MAGTAG.add_text( text_font="/fonts/Deutsch-Gothic-14.bdf", text_position=( 55, 60, ), text_wrap=14, text_anchor_point=(0.5, 0.5), text_scale=1, line_spacing=0.9, is_data=False, ) MAGTAG.add_text( text_font="/fonts/Deutsch-Gothic-14.bdf", text_position=( 55, 85, ), text_anchor_point=(0.5, 0.5), text_scale=1, is_data=False,
import json import re from adafruit_magtag.magtag import MagTag # You can test by setting a time.struct here, to pretend its a different day # (tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec, tm_wday, tm_yday, tm_isdst) FAKETIME = False # time.struct_time(2020, 12, 11, 15, 01, 00, 4, 346, -1) BEEP_ON_EVENTSTART = True # beep when the event begins? EVENT_FILE = "events.json" # file containing events USE_24HR_TIME = False # True for 24-hr time on display, false for 12 hour (am/pm) time magtag = MagTag() magtag.add_text( text_font="/fonts/Arial-Bold-12.pcf", text_color=0xFFFFFF, text_position=(2, 112), text_anchor_point=(0, 0), ) # According to Python, monday is index 0...this array will help us track it day_names = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday") events = None with open(EVENT_FILE, 'r') as evfile: events = json.load(evfile) # validate data for i, event in enumerate(events): if not event.get('name'): raise RuntimeError("No name in event %d" % i) if not event.get('day_of_week') or event['day_of_week'] not in day_names:
from adafruit_magtag.magtag import MagTag from adafruit_progressbar.progressbar import ProgressBar # Set up where we'll be fetching data from DATA_SOURCE = "https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/vaccinations/country_data/United%20States.csv" # pylint: disable=line-too-long # Find data for other countries/states here: # https://github.com/owid/covid-19-data/tree/master/public/data/vaccinations magtag = MagTag(url=DATA_SOURCE) magtag.network.connect() magtag.add_text( text_font="/fonts/ncenR14.pcf", text_position=( (magtag.graphics.display.width // 2) - 1, 8, ), text_anchor_point=(0.5, 0.5), is_data=False, ) # Title magtag.add_text( text_font="/fonts/ncenR14.pcf", text_position=( (magtag.graphics.display.width // 2) - 1, 23, ), text_anchor_point=(0.5, 0.5), is_data=False, ) # Date
from adafruit_magtag.magtag import MagTag import re DATA_SOURCE = "http://192.168.1.34:5000/select?first=1&subscription=%5B%22reading%20list%20%24%20is%20%24title%20%24%20%24%22%5D" magtag = MagTag(url=DATA_SOURCE) magtag.network.connect() magtag.add_text( text_position=( (magtag.graphics.display.width // 2) - 1, (magtag.graphics.display.height // 2) - 1, ), text_scale=3, text_anchor_point=(0.5, 0.5), is_data=False, ) try: value = magtag.fetch() print("Response is", value) title = re.search(r"title\":\"(.+)\"", value).group(1) magtag.set_text("Read\n" + title, 0) except (ValueError, RuntimeError) as e: print("Some error occured, retrying! -", e) magtag.exit_and_deep_sleep(60)
else: hour_string = '12' # 0 -> 12 (am) else: hour_string = '{hh:02d}'.format(hh=time_struct.tm_hour) return hour_string + ':{mm:02d}'.format(mm=time_struct.tm_min) # GRAPHICS INITIALIZATION -------------------------------------------------- MAGTAG.graphics.set_background('bitmaps/produce.bmp') # Produce list is inserted at this position MAGTAG.add_text( text_font='/fonts/cursive-smart.pcf', text_position=(3, 2), line_spacing=1.0, text_anchor_point=(0, 0), # top left is_data=False, # we'll set this text manually ) # Add 14-pixel-tall black bar at bottom of display. It's a distinct layer # (not just background) to appear on top of produce list if it runs long. MAGTAG.graphics.splash.append(Rect(0, MAGTAG.graphics.display.height - 14, MAGTAG.graphics.display.width, MAGTAG.graphics.display.height, fill=0x0)) # Center white text label over black bar to show last update time # (Initially a placeholder, string is not assigned to label until later) MAGTAG.add_text( text_font='/fonts/helvB12.pcf', text_position=(MAGTAG.graphics.display.width // 2,
game_data["status"] = "Game status: " + format_available( magtag.network.json_traverse(event, STATUS_LOCATION)) game_data["broadcast"] = format_broadcast( magtag.network.json_traverse(event, BROADCAST_LOCATION)) scores = magtag.network.json_traverse(event, SCORES_LOCATION) is_final = magtag.network.json_traverse(event, IS_FINAL_LOCATION) game_data["score"] = format_score(scores, is_final) sports_data.append(game_data) if reset_game_number or current_game > len(sports_data): current_game = 0 update_labels() # Sports Name magtag.add_text(text_font="/fonts/Lato-Bold-ltd-25.bdf", text_position=(10, 15), is_data=False) # Game Name magtag.add_text( text_font="/fonts/Arial-Bold-12.pcf", text_wrap=35, line_spacing=0.75, text_position=(10, 70), is_data=False, ) # Date magtag.add_text(text_font="/fonts/Arial-12.bdf", text_position=(10, 40), is_data=False)
NEWHOSP_LOCATION = [0, 'hospitalizedIncrease'] ALLDEATH_LOCATION = [0, 'death'] NEWDEATH_LOCATION = [0, 'deathIncrease'] magtag = MagTag( url=DATA_SOURCE, json_path=(DATE_LOCATION, NEWPOS_LOCATION, CURRHOSP_LOCATION, NEWHOSP_LOCATION, ALLDEATH_LOCATION, NEWDEATH_LOCATION), ) magtag.network.connect() # All positive magtag.add_text( text_font="Arial-Bold-12.bdf", text_position=(10, 15), text_transform=lambda x: "Date: {}".format(x[0:10]), ) # Positive increase magtag.add_text( text_font="Arial-Bold-12.bdf", text_position=(10, 35), text_transform=lambda x: "New positive: {:,}".format(x), ) # Curr hospitalized magtag.add_text( text_font="Arial-Bold-12.bdf", text_position=(10, 55), text_transform=lambda x: "Current Hospital: {:,}".format(x), ) # Change in hospitalized
False, )) # we dont know day of week/year or DST # Set up where we'll be fetching data from # Check http://worldtimeapi.org/timezones for valid values # pylint: disable=line-too-long DATA_SOURCE = "http://worldtimeapi.org/api/timezone/America/New_York" #DATA_SOURCE = "http://worldtimeapi.org/api/timezone/Europe/Stockholm" magtag = MagTag() magtag.network.connect() magtag.add_text( text_font="Arial-Bold-24.bdf", text_position=( 10, (magtag.graphics.display.height // 2) - 1, ), line_spacing=0.85, ) magtag.graphics.qrcode(b"https://buildbackbetter.com/", qr_size=3, x=200, y=25) timestamp = None lasttimefetch_stamp = None while True: if not lasttimefetch_stamp or (time.monotonic() - lasttimefetch_stamp) > 3600: try: # America/New_York - 2020-11-15T11:14:49.970836-05:00 # Europe/Stockholm - 2020-11-15T17:15:01.186119+01:00 response = magtag.network.requests.get(DATA_SOURCE)
def days_in_year(date_obj): # check for leap year if (date_obj.tm_year % 100 != 0 or date_obj.tm_year % 400 == 0) and date_obj.tm_year % 4 == 0: return 366 return 365 magtag = MagTag() magtag.network.connect() magtag.add_text( text_font="/fonts/epilogue18.bdf", text_position=( (magtag.graphics.display.width // 2) - 1, 24, ), text_anchor_point=(0.5, 0.5), is_data=False, ) magtag.set_text("Year Progress:", auto_refresh=False) magtag.add_text( text_font="/fonts/epilogue18.bdf", text_position=( (magtag.graphics.display.width // 2) - 1, 55, ), text_anchor_point=(0.5, 0.5), is_data=False, )
def text_transform(val): return "Translated: {}%".format(val) magtag = MagTag( url=DATA_SOURCE, json_path=DATA_LOCATION, ) magtag.network.connect() magtag.add_text( text_font="fonts/leaguespartan18.bdf", text_position=( (magtag.graphics.display.width // 2) - 1, 42, ), text_scale=1, text_transform=text_transform, text_anchor_point=(0.5, 0.5), ) bottom_lbl_txt = "hosted.weblate.org/projects/circuitpython/" magtag.add_text( text_font="fonts/leaguespartan11.bdf", text_position=( (magtag.graphics.display.width // 2) - 1, (magtag.graphics.display.height) - 8, ), text_scale=1, text_transform=text_transform, text_anchor_point=(0.5, 1.0),
return "%s %d, %d, at %s" % (months[month-1], day, year, timestring) def Humidity_transform(val2): if val2 == None: return "Details: To Be Determined" return "Humidity: " + str(val2) # Set up the MagTag with the JSON data parameters magtag = MagTag( url=DATA_SOURCE, json_path=(reading_time, reading_Temperature, reading_Humidity) ) magtag.add_text( text_font="/fonts/Lato-Bold-ltd-25.bdf", text_position=(10, 15), is_data=False ) # Display heading text below with formatting above magtag.set_text("5th Wheel") # Formatting for the Time text magtag.add_text( text_font="/fonts/Arial-Bold-12.pcf", text_position=(10, 38), text_transform=time_transform ) # Formatting for the Temperature text magtag.add_text( text_font="/fonts/Arial-Bold-12.pcf",
raise ImportError( "Please add your Adafruit IO and WiFi secrets into secrets.py. Exiting." ) device = MagTag() scd = SCD30(board.I2C()) tsl = TSL2591(board.I2C()) # We'll connect this MagTag to the internet if we need to use Adafruit IO connectivity. # device.network.connect() device.add_text( text_font=terminalio.FONT, text_position=( 10, (device.graphics.display.height // 2) - 1, ), text_scale=1, ) device.set_text( "Select a mode:\na. CO2 and Temperature\nb. Humidity\nc.Infrared Light\nd.Visible Light\nWant to start over? Press Reset to go back." ) buttons = device.peripherals.buttons while True: # When button A is pressed, then show CO2 and temperature if device.peripherals.button_a_pressed: co2 = scd.CO2
import time import terminalio from adafruit_magtag.magtag import MagTag from secrets import secrets DATA_SOURCE = 'https://api.openweathermap.org/data/2.5/weather?zip=52601,us&units=imperial&appid=' + \ secrets['open_weather_key'] magtag = MagTag(url=DATA_SOURCE, json_path=(["name"], ["main", "temp"], ["main", "temp_max"], ["main", "temp_min"], ["weather", 0, "main"], ["wind", "speed"])) magtag.add_text(text_position=(5, 10), text_scale=2, is_data=False) magtag.get_local_time() now = time.localtime() magtag.set_text("{}/{}/{} {}:{}".format(*now)) 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),
("Scorpio", 0), # black! ("Sagittarius", (128,0,128)), # purple ("Capricorn", (165,42,42)) # brown ) horoscopes = json.loads(open("horoscopes.json").read()) #verses = json.loads(open("verses.json").read()) #print(verses) #print(horoscopes) # main text, index 0 magtag.add_text( text_font = terminalio.FONT if PLAINFONT else "Arial-Bold-24.bdf", text_position=( magtag.graphics.display.width // 2, 10, ), text_scale = 3 if PLAINFONT else 1, line_spacing=1, text_anchor_point=(0.5, 0), ) # button labels, add all 4 in one loop for x_coord in (10, 75, 150, 220): magtag.add_text( text_font = terminalio.FONT if PLAINFONT else "Arial-12.bdf", text_position=(x_coord, magtag.graphics.display.height - 10), line_spacing=1.0, text_anchor_point=(0, 1), ) # large horoscope text, index 5
tail_length=stripCometTailLen), ))), AnimationGroup(Solid(boardPixels, WHITE), Solid(stripPixels, AMBER)), AnimationGroup( Solid(boardPixels, AMBER), Solid(stripPixels, 0), ), auto_clear=True, ) ### Background & Text ### # Draws the background image and static text magtag.set_background("/led.bmp") magtag.add_text(text_color=0x000000, text_position=(5, 10), text_scale=2) magtag.set_text("Light Selector:", auto_refresh=False) magtag.add_text(text_color=0x000000, text_position=(25, 65)) magtag.set_text("A: Rainbow Cycle\n" "B: Comet\n" "C: Amber\n" "D: Dim", index=1, auto_refresh=False) magtag.add_text(text_color=0x000000, text_position=(0, 120)) magtag.set_text(" A B C D", index=2) magtag.add_text(text_color=0x000000, text_position=(250, 10)) magtag.set_text("{} V".format("-4.20"), index=3)
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries # # SPDX-License-Identifier: Unlicense import time from adafruit_magtag.magtag import MagTag magtag = MagTag() magtag.add_text( text_position=( 50, (magtag.graphics.display.height // 2) - 1, ), text_scale=3, ) magtag.set_text("Hello World") button_colors = ((255, 0, 0), (255, 150, 0), (0, 255, 255), (180, 0, 255)) button_tones = (1047, 1318, 1568, 2093) while True: for i, b in enumerate(magtag.peripherals.buttons): if not b.value: print("Button %c pressed" % chr((ord("A") + i))) magtag.peripherals.neopixel_disable = False magtag.peripherals.neopixels.fill(button_colors[i]) magtag.peripherals.play_tone(button_tones[i], 0.25) break else: magtag.peripherals.neopixel_disable = True
# SPDX-FileCopyrightText: 2020 Eva Herrada for Adafruit Industries # # SPDX-License-Identifier: MIT import time import terminalio from adafruit_magtag.magtag import MagTag magtag = MagTag() magtag.peripherals.neopixel_disable = False magtag.add_text( text_font=terminalio.FONT, text_position=(140, 55), text_scale=7, text_anchor_point=(0.5, 0.5), ) magtag.set_text("00:00") # Function that makes the neopixels display the seconds left def update_neopixels(seconds): n = seconds // 15 for j in range(n): magtag.peripherals.neopixels[3 - j] = (128, 0, 0) magtag.peripherals.neopixels[3 - n] = (int( ((seconds / 15) % 1) * 128), 0, 0) alarm_set = False
TWEET_TEXT = [0, "full_text"] TWEET_FULL_NAME = [0, "user", "name"] TWEET_HANDLE = [0, "user", "screen_name"] magtag = MagTag(url=DATA_SOURCE, json_path=(TWEET_FULL_NAME, TWEET_HANDLE, TWEET_TEXT)) # Set Twitter OAuth2.0 Bearer Token bearer_token = secrets["twitter_bearer_token"] magtag.set_headers({"Authorization": "Bearer " + bearer_token}) # Display setup magtag.set_background("/images/background.bmp") # Twitter name magtag.add_text( text_position=(70, 10), text_font="/fonts/Arial-Bold-12.pcf", ) # Twitter handle (@username) 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=(
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries # # SPDX-License-Identifier: Unlicense import time import terminalio from adafruit_magtag.magtag import MagTag magtag = MagTag() magtag.add_text( text_font=terminalio.FONT, text_position=( 50, (magtag.graphics.display.height // 2) - 1, ), text_scale=3, ) magtag.set_text("Hello World") buttons = magtag.peripherals.buttons button_colors = ((255, 0, 0), (255, 150, 0), (0, 255, 255), (180, 0, 255)) button_tones = (1047, 1318, 1568, 2093) timestamp = time.monotonic() while True: for i, b in enumerate(buttons): if not b.value: print("Button %c pressed" % chr((ord("A") + i))) magtag.peripherals.neopixel_disable = False magtag.peripherals.neopixels.fill(button_colors[i])
EVENT_MINUTE = 00 # we'll make a python-friendly structure event_time = time.struct_time((EVENT_YEAR, EVENT_MONTH, EVENT_DAY, EVENT_HOUR, EVENT_MINUTE, 0, # we don't track seconds -1, -1, False)) # we dont know day of week/year or DST # Set up where we'll be fetching data from # pylint: disable=line-too-long DATA_SOURCE = "http://worldtimeapi.org/api/timezone/America/New_York" magtag = MagTag() magtag.network.connect() magtag.add_text( text_font="Arial-Bold-24.bdf", text_position=(10, 25), line_spacing=0.85, ) magtag.graphics.qrcode(b"https://buildbackbetter.com/", qr_size=3, x=200, y=25) timestamp = None lasttimefetch_stamp = None while True: if not lasttimefetch_stamp or (time.monotonic() - lasttimefetch_stamp) > 3600: try: response = magtag.network.requests.get(DATA_SOURCE) datetime_str = response.json()['datetime'] datesplit = datetime_str.split("-") year = int(datesplit[0])
def text_transform(val): return "Bitcoin: $%d" % val magtag = MagTag( url=DATA_SOURCE, json_path=DATA_LOCATION, ) magtag.network.connect() magtag.add_text( text_font=terminalio.FONT, text_position=( (magtag.graphics.display.width // 2) - 1, (magtag.graphics.display.height // 2) - 1, ), text_scale=3, text_transform=text_transform, text_anchor_point=(0.5, 0.5), ) magtag.preload_font(b"$012345789") # preload numbers magtag.preload_font((0x00A3, 0x20AC)) # preload gbp/euro symbol timestamp = None while True: if not timestamp or (time.monotonic() - timestamp) > 60: # once every 60 seconds... try: value = magtag.fetch()