test specific game monitoring
This commit is contained in:
+53
-30
@@ -311,6 +311,14 @@ def draw_all_games(canvas, games, start_index):
|
|||||||
for row in range(32):
|
for row in range(32):
|
||||||
canvas.SetPixel(offset + 63, row, 40, 40, 40)
|
canvas.SetPixel(offset + 63, row, 40, 40, 40)
|
||||||
|
|
||||||
|
def draw_single_game(canvas, game):
|
||||||
|
league = game["league"]
|
||||||
|
home_logo = load_logo(league, game["home"])
|
||||||
|
away_logo = load_logo(league, game["away"])
|
||||||
|
|
||||||
|
draw_logo(canvas, away_logo, 0, 0)
|
||||||
|
draw_logo(canvas, home_logo, 0, 16)
|
||||||
|
|
||||||
|
|
||||||
# --- Main loop ---
|
# --- Main loop ---
|
||||||
def run():
|
def run():
|
||||||
@@ -324,46 +332,61 @@ def run():
|
|||||||
last_switch = time()
|
last_switch = time()
|
||||||
|
|
||||||
current_games = get_all_scores()
|
current_games = get_all_scores()
|
||||||
|
preferred_team = [
|
||||||
|
"BUF",
|
||||||
|
"TOR",
|
||||||
|
"TB"
|
||||||
|
]
|
||||||
|
preferred_game = []
|
||||||
for game in current_games:
|
for game in current_games:
|
||||||
print(game)
|
print(game)
|
||||||
|
if game['home'] in preferred_team or game['away'] in preferred_team:
|
||||||
|
if game['status'] != 'Final':
|
||||||
|
preferred_game_on = True
|
||||||
|
preferred_game.append(game)
|
||||||
|
|
||||||
while True:
|
if preferred_game_on:
|
||||||
now = time()
|
while True:
|
||||||
|
draw_single_game(canvas, preferred_game[0])
|
||||||
|
sleep(0.03)
|
||||||
|
else:
|
||||||
|
while True:
|
||||||
|
now = time()
|
||||||
|
|
||||||
if now - last_fetch > 30:
|
if now - last_fetch > 30:
|
||||||
new_games = get_all_scores()
|
new_games = get_all_scores()
|
||||||
|
|
||||||
# update prev_scores
|
# update prev_scores
|
||||||
for game in new_games:
|
for game in new_games:
|
||||||
gid = game["id"]
|
gid = game["id"]
|
||||||
try:
|
try:
|
||||||
prev_scores[gid] = (
|
prev_scores[gid] = (
|
||||||
int(game["away_score"]),
|
int(game["away_score"]),
|
||||||
int(game["home_score"]),
|
int(game["home_score"]),
|
||||||
)
|
)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
games = new_games
|
games = new_games
|
||||||
last_fetch = now
|
last_fetch = now
|
||||||
if not games:
|
if not games:
|
||||||
current_page = 0
|
current_page = 0
|
||||||
|
|
||||||
if games and now - last_switch > page_display_time:
|
if games and now - last_switch > page_display_time:
|
||||||
current_page = (current_page + 4) % max(len(games), 1)
|
current_page = (current_page + 4) % max(len(games), 1)
|
||||||
last_switch = now
|
last_switch = now
|
||||||
|
|
||||||
canvas.Clear()
|
canvas.Clear()
|
||||||
|
|
||||||
if games:
|
if games:
|
||||||
draw_all_games(canvas, games, current_page)
|
draw_all_games(canvas, games, current_page)
|
||||||
else:
|
else:
|
||||||
graphics.DrawText(
|
graphics.DrawText(
|
||||||
canvas, font, 10, 22, graphics.Color(Colors.RED), "No games today"
|
canvas, font, 10, 22, graphics.Color(Colors.RED), "No games today"
|
||||||
)
|
)
|
||||||
|
|
||||||
canvas = matrix.SwapOnVSync(canvas)
|
canvas = matrix.SwapOnVSync(canvas)
|
||||||
sleep(0.03)
|
sleep(0.03)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user