# Set to the amount of time to deep sleep for, in minutes SLEEP_TIME = 15 # Set up where we'll be fetching data from DATA_SOURCE = ("https://api.twitter.com/1.1/statuses/user_timeline.json?" "screen_name=%s&count=1&tweet_mode=extended" % TWITTER_USERNAME) 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,
import random from adafruit_magtag.magtag import MagTag # Set up where we'll be fetching data from DATA_SOURCE = "https://icanhazdadjoke.com/" JOKE_LOCATION = ["joke"] # in seconds, we can refresh about 100 times on a battery TIME_BETWEEN_REFRESHES = 1 * 60 * 60 # one hour delay magtag = MagTag( url=DATA_SOURCE, json_path=(JOKE_LOCATION), ) magtag.set_headers({"Accept": "application/json"}) magtag.graphics.set_background("/bmps/magtag_shower_bg.bmp") # joke in bold text, with text wrapping magtag.add_text( text_font="/fonts/Arial-Bold-12.pcf", 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 )