m0ranwad / nba-led-scoreboard

NBA LED scoreboard! This project displays matches and scores for all of the current day's NBA action
GNU General Public License v3.0
5 stars 3 forks source link

Add text for teams names instead of Logos. #14

Open alexanderthebadatcoding opened 9 months ago

alexanderthebadatcoding commented 9 months ago

Have the option to show text instead of the logos I think I figured this out. First add the team color from the ESPN api and a way to convert the hex code to RGB:

def hex_to_rgb_with_default(hex_color, default="#FFFFFF"):
    """
    Convert a hex color code to RGB format with a default value.

    Parameters:
        hex_color (str): The hex color code, e.g., "#ff5f05".
        default (str): The default hex color code, e.g., "#FFFFFF".

    Returns:
        tuple: A tuple representing the RGB values, e.g., (255, 95, 5).
    """
    try:
        #hex_color = hex_color.lstrip('#')
        rgb_values = tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
        return rgb_values
    except ValueError:
        print(f"Error: Invalid hex color code '{hex_color}'. Using default white.")
        return hex_to_rgb_with_default(default)

add to _for game_info in gamesdata:

            if 'color' in competition_info['competitors'][0]['team']:
                home_color_code = competition_info['competitors'][0]['team']['color']
            else:
                home_color_code = 'FFFFFF'

            if 'color' in competition_info['competitors'][1]['team']:
                away_color_code = competition_info['competitors'][1]['team']['color']
            else:
                away_color_code = 'FFFFFF'

            # Now you can use the hex_to_rgb_with_default function to convert the color code
            home_rgb_values = hex_to_rgb_with_default(home_color_code)
            away_rgb_values = hex_to_rgb_with_default(away_color_code)
            # print(home_rgb_values, away_rgb_values)

in games:

'homecolor': home_rgb_values,
 'awaycolor': away_rgb_values,

then in the renderer/main.py file edit the display_team_logos() :

        away_team_logo = None
        home_team_logo = None
        try:
            if self.data.nba_logos:
                self.draw.multiline_text(away_logo_position, game['awayteam'], fill=game['awaycolor'], font=self.font)
                self.draw.multiline_text(home_logo_position, game['hometeam'], fill=game['homecolor'], font=self.font)
                self.canvas.SetImage(self.image, 0, 0)

this is just a rough idea and will need to be tested more, but I think it should work.

alexanderthebadatcoding commented 9 months ago

Utah and the Nets have black as the teams colors, so it could be the alternate color for those teams.