MagTag_CountdownCelebration - fix text postion for updated display_text library
@@ -12,9 +12,19 @@ EVENT_DAY = 20
EVENT_HOUR = 12
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
+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
@@ -25,12 +35,11 @@ magtag.network.connect()
magtag.add_text(
text_font="Arial-Bold-24.bdf",
- text_position=(10, 25),
+ 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)
+magtag.graphics.qrcode(b"https://buildbackbetter.com/", qr_size=3, x=200, y=25)
timestamp = None
lasttimefetch_stamp = None
@@ -38,7 +47,7 @@ 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']
+ datetime_str = response.json()["datetime"]
datesplit = datetime_str.split("-")
year = int(datesplit[0])
month = int(datesplit[1])
@@ -48,7 +57,9 @@ while True:
hours = int(timesplit[0])
minutes = int(timesplit[1])
seconds = int(float(timesplit[2].split("-")[0]))
- rtc.RTC().datetime = time.struct_time((year, month, mday, hours, minutes, seconds, 0, 0, False))
+ rtc.RTC().datetime = time.struct_time(
+ (year, month, mday, hours, minutes, seconds, 0, 0, False)
+ )
lasttimefetch_stamp = time.monotonic()
except (ValueError, RuntimeError) as e:
print("Some error occured, retrying! -", e)
@@ -77,10 +88,14 @@ while True:
hours_remaining = remaining % 24
remaining //= 24
days_remaining = remaining
- print("%d days, %d hours, %d minutes and %s seconds" %
- (days_remaining, hours_remaining, mins_remaining, secs_remaining))
- magtag.set_text("%d Days\n%d Hours\n%d Mins" %
- (days_remaining, hours_remaining, mins_remaining))
+ print(
+ "%d days, %d hours, %d minutes and %s seconds"
+ % (days_remaining, hours_remaining, mins_remaining, secs_remaining)
+ )
+ magtag.set_text(
+ "%d Days\n%d Hours\n%d Mins"
+ % (days_remaining, hours_remaining, mins_remaining)
+ )
timestamp = time.monotonic()
# wait around
time.sleep(1)
