add more games

This commit is contained in:
2026-05-02 20:53:54 -04:00
parent 9d02d7525c
commit 6867679ca5
+30 -35
View File
@@ -21,7 +21,6 @@ canvas = matrix.CreateFrameCanvas()
font = graphics.Font() font = graphics.Font()
font.LoadFont("/usr/local/share/7x13.bdf") font.LoadFont("/usr/local/share/7x13.bdf")
# A smaller font for status text
font_small = graphics.Font() font_small = graphics.Font()
font_small.LoadFont("/usr/local/share/5x7.bdf") font_small.LoadFont("/usr/local/share/5x7.bdf")
@@ -41,9 +40,8 @@ def load_logo(league, abbr):
return logo_cache[key] return logo_cache[key]
path = os.path.join(LOGO_DIR, f"{key}.png") path = os.path.join(LOGO_DIR, f"{key}.png")
print(f"Looking for logo at: {path}, exists: {os.path.exists(path)}")
if not os.path.exists(path): if not os.path.exists(path):
print(f"Logo not found: {path}")
logo_cache[key] = None logo_cache[key] = None
return None return None
@@ -58,9 +56,7 @@ def load_logo(league, abbr):
def draw_logo(canvas, img, x, y): def draw_logo(canvas, img, x, y):
if img is None: if img is None:
print("Logo is None!")
return return
print(f"Drawing logo {img.size} at {x},{y}")
for px in range(img.width): for px in range(img.width):
for py in range(img.height): for py in range(img.height):
r, g, b = img.getpixel((px, py)) r, g, b = img.getpixel((px, py))
@@ -99,41 +95,41 @@ def get_all_scores():
games += get_scores("basketball", "nba") games += get_scores("basketball", "nba")
return games return games
# --- Draw a single game in stacked layout --- # --- Draw all games across all panels ---
# Layout per panel (64px wide, 32px tall): def draw_all_games(canvas, games, start_index):
# Top half (rows 0-15): [16x16 away logo] [away abbr] [away score] for i in range(4): # one per panel
# Bottom half (rows 16-31): [16x16 home logo] [home abbr] [home score] game_index = (start_index + i) % len(games)
# Status text scrolls across the bottom row game = games[game_index]
offset = i * 64 # each panel is 64px wide
def draw_game(canvas, game): league = game["league"]
league = game["league"] away_logo = load_logo(league, game["away"])
home_logo = load_logo(league, game["home"])
away_logo = load_logo(league, game["away"]) # Draw logos
home_logo = load_logo(league, game["home"]) draw_logo(canvas, away_logo, offset + 0, 0)
draw_logo(canvas, home_logo, offset + 0, 16)
# Draw logos # Draw team abbreviations
draw_logo(canvas, away_logo, 0, 0) # top left graphics.DrawText(canvas, font_small, offset + 18, 11, white, game["away"])
draw_logo(canvas, home_logo, 0, 16) # bottom left graphics.DrawText(canvas, font_small, offset + 18, 27, white, game["home"])
# Draw team abbreviations # Draw scores
graphics.DrawText(canvas, font_small, 18, 11, white, game["away"]) graphics.DrawText(canvas, font, offset + 40, 13, yellow, str(game["away_score"]))
graphics.DrawText(canvas, font_small, 18, 27, white, game["home"]) graphics.DrawText(canvas, font, offset + 40, 29, yellow, str(game["home_score"]))
# Draw scores # Draw a subtle divider between panels
graphics.DrawText(canvas, font, 40, 13, yellow, str(game["away_score"])) if i < 3:
graphics.DrawText(canvas, font, 40, 29, yellow, str(game["home_score"])) for row in range(32):
canvas.SetPixel(offset + 63, row, 40, 40, 40)
# Draw status in grey at far right if short enough, otherwise truncate
status = game["status"][:10]
graphics.DrawText(canvas, font_small, 130, 11, grey, status)
# --- Main loop --- # --- Main loop ---
def run(): def run():
global canvas global canvas
games = [] games = []
last_fetch = 0 last_fetch = 0
current_game = 0 current_page = 0
game_display_time = 8 # seconds per game page_display_time = 8 # seconds per page
last_switch = time.time() last_switch = time.time()
while True: while True:
@@ -144,18 +140,17 @@ def run():
games = get_all_scores() games = get_all_scores()
last_fetch = now last_fetch = now
if not games: if not games:
current_game = 0 current_page = 0
# Switch game every N seconds # Switch page every N seconds
if games and now - last_switch > game_display_time: if games and now - last_switch > page_display_time:
current_game = (current_game + 1) % len(games) current_page = (current_page + 4) % max(len(games), 1)
last_switch = now last_switch = now
canvas.Clear() canvas.Clear()
if games: if games:
current_game = current_game % len(games) draw_all_games(canvas, games, current_page)
draw_game(canvas, games[current_game])
else: else:
graphics.DrawText(canvas, font, 10, 22, red, "No games today") graphics.DrawText(canvas, font, 10, 22, red, "No games today")