Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions MagTag/MagTag_Literature_Clock/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def find_lines_to_show(all_lines, important_passage):
hour = f"{now.tm_hour:02d}"

# open the data file for the current hour
with open(f"split_data_compressed/{hour}.csv.gz", "rb") as f:
with open(f"quotes_data/{hour}.csv.gz", "rb") as f:
# read and unzip the data
compressed_data = f.read()
rows = zlib.decompress(compressed_data).split(b"\n")
Expand Down Expand Up @@ -212,9 +212,6 @@ def find_lines_to_show(all_lines, important_passage):
# extract the book title
title = parts[3]

# set the text in the book info label to show the title and author
book_info_lbl.text = f"{title} - {author}"

# extract the current time reference string
time_part = parts[1]

Expand Down Expand Up @@ -243,19 +240,31 @@ def find_lines_to_show(all_lines, important_passage):
# Temporary version of final visible quote joined with spaces instead of newlines,
# so we can search for the time_part without worrying about potential newlines.
shown_quote_with_spaces = " ".join(
quote_lines[first_line_to_show : first_line_to_show + 7]
quote_lines[first_line_to_show: first_line_to_show + 7]
)

# find the current time reference within the quote that will be shown
time_start_index = shown_quote_with_spaces.find(time_part)
time_end_index = time_start_index + len(time_part)

# wrap the quote to be shown to multiple lines and set it on the label
quote_lbl.text = "\n".join(quote_lines[first_line_to_show : first_line_to_show + 7])
quote_lbl.text = "\n".join(quote_lines[first_line_to_show: first_line_to_show + 7])

# accent the part of the quote that references the current time
quote_lbl.add_accent_range(time_start_index, time_end_index, 4, 3, "outline")

# show title and author in the book info label
# allow it to split to two lines if the quote is short enough
if len(quote_lines) <= 6:
book_info = f"{title} - {author}"
book_info_lbl.text = "\n".join(wrap_text_to_pixels(
book_info,
display.width - 4,
terminalio.FONT,
))
else:
book_info_lbl.text = f"{title} - {author}"

# update the display and wait 60 seconds
display.refresh()
time.sleep(60)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.