Adabox 016 - BANNED scoreboard

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
belsonc
 
Posts: 38
Joined: Tue Sep 15, 2020 8:39 pm

Adabox 016 - BANNED scoreboard

Post by belsonc »

So I live outside of NYC, but my favorite football team is the Kansas City Chiefs. Their games aren't always on TV, and I don't necessarily want to be pulling out my phone if I just want to see the score. I looked around a little and found that the BANNED has a json file with game information, so to get a little practice, I made an BANNED scoreboard customizable for whatever team you follow. The team abbreviation and score are in the team's colors (even though the picture doesn't look like it), and even though it's not implemented here, the json file itself also has other information including quarter and time remaining.

Right now, it updates every 15 seconds, but that's only because I was getting error messages I was trying to debug (thanks again, @dastels) and didn't want to wait 60-90 seconds for the errors to show. If anyone wants, I can post the code - let me know. (and DFH 60 is my late best friend's favorite beer, I know he'd appreciate this project, so I posted that picture on his FB wall... if it violates any rules or anything, let me know and I'll replace it.)

-CB
Attachments
scoreboard.jpg
scoreboard.jpg (144.13 KiB) Viewed 946 times

User avatar
raydz
 
Posts: 6
Joined: Mon Mar 25, 2013 1:51 am

Re: Adabox 016 - BANNED scoreboard

Post by raydz »

Yes, please!

User avatar
belsonc
 
Posts: 38
Joined: Tue Sep 15, 2020 8:39 pm

Re: Adabox 016 - BANNED scoreboard

Post by belsonc »

Probably not the cleanest - I wouldn't be surprised if some things could be implemented better/smoother/cleaner/whatever, but:

Code: Select all

import terminalio
import displayio
import time
import adafruit_display_text.label
import json
import adafruit_requests as requests
import board
import rgbmatrix
import framebufferio
from adafruit_matrixportal.matrixportal import MatrixPortal
from adafruit_matrixportal.network import Network
from adafruit_bitmap_font import bitmap_font



#INITIALIZE DISPLAY SOMEWHERE
matrixportal = MatrixPortal(status_neopixel=board.NEOPIXEL, debug=False)

type_face = bitmap_font.load_font('/fonts/helvR10.bdf')
team_y = 8
score_y = 18
away_x = 2
home_x = 32
json_Source = 'http://static.BANNED.com/liveupdate/scores/scores.json'

#https://teamcolorcodes.com/BANNED-team-color-codes/
team_Colors={
            'ARI': {'team' : 0x97233F, 'score' : 0xFFB612},
            'ATL': {'team' : 0xA71930, 'score' : 0xA5ACAF},
            'BAL': {'team' : 0x241773, 'score' : 0x9E7C0C},
            'BUF': {'team' : 0x00338D, 'score' : 0xC60C30},
            'CAR': {'team' : 0x0085CA, 'score' : 0xBFC0BF},
            'CHI': {'team' : 0x0B162A, 'score' : 0xC83803},
            'CIN': {'team' : 0xFB4F14, 'score' : 0xFB4F14},
            'CLE': {'team' : 0x311D00, 'score' : 0xFF3C00},
            'DAL': {'team' : 0x003594, 'score' : 0x869397},
            'DEN': {'team' : 0xFB4F14, 'score' : 0x002244},
            'DET': {'team' : 0x0076B6, 'score' : 0xB0B7BC},
            'GB': {'team' : 0x203731, 'score' : 0xFFB612},
            'HOU': {'team' : 0xA71930, 'score' : 0xA71930},
            'IND': {'team' : 0x002C5F, 'score' : 0xA2AAAD},
            'JAC': {'team' : 0xD7A22A, 'score' : 0x006778},
            'KC': {'team' : 0xE31837, 'score' : 0xFFB81C},
            'LA': {'team' : 0x003594, 'score' : 0xFFA300},
            'LAC': {'team' : 0xFFC20E, 'score' : 0x0080C6},
            'MIA': {'team' : 0x008E97, 'score' : 0xFC4C02},
            'MIN': {'team' : 0x4F2683, 'score' : 0xFFC62F},
            'NE': {'team' : 0x002244, 'score' : 0xB0B7BC},
            'NO': {'team' : 0xD3BC8D, 'score' : 0xD3BC8D},
            'NYG': {'team' : 0x0B2265, 'score' : 0xA71930},
            'NYJ': {'team' : 0x125740, 'score' : 0xFFFFFF},
            'LV': {'team' : 0xA5ACAF, 'score' : 0xA5ACAF},
            'PHI': {'team' : 0x004C54, 'score' : 0xA5ACAF},
            'PIT': {'team' : 0xFFB612, 'score' : 0xFFB612},
            'SF': {'team' : 0xAA0000, 'score' : 0xB3995D},
            'SEA': {'team' : 0x002244, 'score' : 0xA5ACAF},
            'TB': {'team' : 0xD50A0A, 'score' : 0xB1BABF},
            'TEN': {'team' : 0xC8102E, 'score' : 0x4B92DB},
            'WAS': {'team' : 0x773141, 'score' : 0xFFB612}}



while True:
    json_Data = matrixportal.fetch(json_Source)
    json_Data1 = json.loads(json_Data)
    for game_ID in json_Data1:
        #print(json_Data1[game_ID])
        if json_Data1[game_ID]['home']['abbr'] == 'DET' or json_Data1[game_ID]['away']['abbr'] == 'DET':
            visitor_Team = json_Data1[game_ID]['away']['abbr']
            home_Team = json_Data1[game_ID]['home']['abbr']
            visitor_Points = json_Data1[game_ID]['away']['score']['T']
            home_Points = json_Data1[game_ID]['home']['score']['T']
            current_Quarter = json_Data1[game_ID]['qtr']
            game_Clock = json_Data1[game_ID]['clock']

#look for the chiefs in the returned object
#use the quote board information at the least for this



    matrixportal.add_text(text_position=(away_x,team_y),text_font=terminalio.FONT,text_color=team_Colors[visitor_Team].get('team'))
    matrixportal.set_text(str(visitor_Team),0)
    print("visitor name")
    matrixportal.add_text(text_position=(home_x,team_y),text_font=terminalio.FONT,text_color=team_Colors[home_Team].get('team'))
    matrixportal.set_text(str(home_Team),1)
    print("home name")
    matrixportal.add_text(text_position=(away_x,score_y),text_font=terminalio.FONT,text_color=team_Colors[visitor_Team].get('score'))
    matrixportal.set_text(str(visitor_Points),2)
    print("visitor score")
    matrixportal.add_text(text_position=(home_x,score_y),text_font=terminalio.FONT,text_color=team_Colors[home_Team].get('score'))
    matrixportal.set_text(str(home_Points),3)
    print("home score")

    print("Made it to the bottom")
    json_Data=""
#copy relevant information into appropriate variables, including setting colors


#display information


#refresh every... minute?  2 minutes?
    time.sleep(15) #every minute and a half for the time being

User avatar
Powderjockey
 
Posts: 189
Joined: Fri Mar 31, 2017 10:14 pm

Re: Adabox 016 - BANNED scoreboard

Post by Powderjockey »

@belsonc do you have a list of the files in the /lib directory? I'm just getting the Curcuitpython logo and probably missing the proper lib files.

Thanks for this.

User avatar
belsonc
 
Posts: 38
Joined: Tue Sep 15, 2020 8:39 pm

Re: Adabox 016 - BANNED scoreboard

Post by belsonc »

Running around a little, but I'll have the info to you tomorrow. (not sure where you are, I'm in NY and it's 11.30pm here.)

User avatar
belsonc
 
Posts: 38
Joined: Tue Sep 15, 2020 8:39 pm

Re: Adabox 016 - BANNED scoreboard

Post by belsonc »

As promised - enjoy. :-)
Attachments
scoreboard lib folder.PNG
scoreboard lib folder.PNG (20.88 KiB) Viewed 819 times

User avatar
Powderjockey
 
Posts: 189
Joined: Fri Mar 31, 2017 10:14 pm

Re: Adabox 016 - BANNED scoreboard

Post by Powderjockey »

Thanks. Was missing two of the .mpy's.

It did run, kind of. It would show the score, then flicker 4 times, then show Blinka and the error board. During each flicker, the board did not refresh and the scores were not readable.

User avatar
belsonc
 
Posts: 38
Joined: Tue Sep 15, 2020 8:39 pm

Re: Adabox 016 - BANNED scoreboard

Post by belsonc »

Hm - weird. Never had the issue with it not refreshing, it would flicker then the score would come back up. I did get the blinka issue on occasion - I don't remember if it was an issue modem-side or getting the file-side - but considering this wasn't mission critical and all I'd have to do to fix it was walk across the room, I didn't think it was that big of a deal. I'm sure there's a way to make the code more robust, but given I did this in free time, I was just happy to get it up and running, you know?

User avatar
Powderjockey
 
Posts: 189
Joined: Fri Mar 31, 2017 10:14 pm

Re: Adabox 016 - BANNED scoreboard

Post by Powderjockey »

I thank you for your quick writing skills. I have programming skills, to which I wish I did, but know enough to follow the script to know what is happening. To fix anything, nope.

User avatar
Powderjockey
 
Posts: 189
Joined: Fri Mar 31, 2017 10:14 pm

Re: Adabox 016 - BANNED scoreboard

Post by Powderjockey »

belsonc wrote:Hm - weird. Never had the issue with it not refreshing, it would flicker then the score would come back up. I did get the blinka issue on occasion - I don't remember if it was an issue modem-side or getting the file-side - but considering this wasn't mission critical and all I'd have to do to fix it was walk across the room, I didn't think it was that big of a deal. I'm sure there's a way to make the code more robust, but given I did this in free time, I was just happy to get it up and running, you know?
What version of CircuitPython are you running on the matrix portal?

User avatar
Powderjockey
 
Posts: 189
Joined: Fri Mar 31, 2017 10:14 pm

Re: Adabox 016 - BANNED scoreboard

Post by Powderjockey »

Trying to spice this script up and changing it to the NHL. I have a url that I can get information from, but it needs a userid and password to get the information. I placed the credentials the secrets.py, but I can't quite figure out how to get the script to access these credentials. I'm receiving a 401 error which I believe is because of the credentials are not being past.

Code: Select all

import terminalio
import displayio
import time
import adafruit_display_text.label
import json
import adafruit_requests as requests
import board
import rgbmatrix
import framebufferio
from adafruit_matrixportal.matrixportal import MatrixPortal
from adafruit_matrixportal.network import Network
from adafruit_bitmap_font import bitmap_font
#from secrets import secrets

try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise
    

# INITIALIZE DISPLAY SOMEWHERE
matrixportal = MatrixPortal(status_neopixel=board.NEOPIXEL, debug=False)

type_face = bitmap_font.load_font("/fonts/helvR10.bdf")
team_y = 8
score_y = 18
awayTeam_x = 2
homeTeam_x = 32

# d = date(datetime.date(datetime.now()))

json_URL = "https://api.mysportsfeeds.com/v1.0/pull/nhl/current/scoreboard.json?fordate=20210319"
print("Fetching json from", json_URL)


# https://teamcolorcodes.com/BANNED-team-color-codes/
team_Colors = {
    "ANA": {"team": 0xF47A38, "score": 0xB9975B},
    "ARI": {"team": 0x8C2633, "score": 0xE2D6B5},
    "BOS": {"team": 0xFFB81C, "score": 0xFFB81C},
    "BUF": {"team": 0x002654, "score": 0xFCB514},
    "CAL": {"team": 0xC8102E, "score": 0xF1BE48},
    "CAR": {"team": 0xCC0000, "score": 0xA2AAAD},
    "CHI": {"team": 0xCF0A2C, "score": 0x00833E},
    "COL": {"team": 0x6F263D, "score": 0xA2AAAD},
    "CBJ": {"team": 0x002654, "score": 0xCE1126},
    "DAL": {"team": 0x006847, "score": 0x8F8F8C},
    "DET": {"team": 0xCE1126, "score": 0xFFFFFF},
    "EDM": {"team": 0x041E42, "score": 0xFF4C00},
    "FLO": {"team": 0x041E42, "score": 0xC8102E},
    "LAK": {"team": 0x2AAAAD, "score": 0xFFFFFF},
    "MIN": {"team": 0xA6192E, "score": 0x154734},
    "MON": {"team": 0xAF1E2D, "score": 0x192168},
    "NAS": {"team": 0xFFB81C, "score": 0x041E42},
    "NJD": {"team": 0xCE1126, "score": 0xFFFFFF},
    "NYI": {"team": 0x00539B, "score": 0xF47D30},
    "NYR": {"team": 0x0038A8, "score": 0xCE1126},
    "OTT": {"team": 0xC52032, "score": 0xC2912C},
    "PHI": {"team": 0xF74902, "score": 0xFFFFFF},
    "PIT": {"team": 0xCFC493, "score": 0xFCB514},
    "STL": {"team": 0x002F87, "score": 0xFCB514},
    "SJS": {"team": 0x006D75, "score": 0xEA7200},
    "SEA": {"team": 0x99D9D9, "score": 0x355464},
    "TBL": {"team": 0x022868, "score": 0xFFFFFF},
    "TOR": {"team": 0x00205B, "score": 0xFFFFFF},
    "VAN": {"team": 0x00205B, "score": 0x00843D},
    "VGK": {"team": 0xB4975A, "score": 0x333F42},
    "WAS": {"team": 0x041E42, "score": 0xC8102E},
    "WIN": {"team": 0x004C97, "score": 0xAC162C},
}

while True:
    json_Data = matrixportal.fetch(json_URL)
    json_Data1 = json.loads(json_Data)
    for ID in json_Data1:
        # print(json_Data1['ID'])
        if (
            json_Data1["ID"]["homeTeam"]["Abbreviation"] == "CAL"
            or json_Data1["ID"]["awayTeam"]["Abbreviation"] == "CAL"
        ):
            awayTeam = json_Data1["ID"]["awayTeam"]["Abbreviation"]
            homeTeam = json_Data1["ID"]["homeTeam"]["Abbreviation"]
            visitor_Score = json_Data1["ID"]["awayTeam"]["awayScore"]
            home_Score = json_Data1["ID"]["homeTeam"]["homeScore"]
            current_Period = json_Data1["ID"]["currentPeriod"]
            game_Clock = json_Data1["ID"]["currentPeriodSecondsRemaining"]

    # look for your team in the returned object
    # use the quote board information at the least for this

    matrixportal.add_text(
        text_position=(awayTeam_x, team_y),
        text_font=terminalio.FONT,
        text_color=team_Colors[awayTeam_Team].get("team"),
    )
    matrixportal.set_text(str(visitor_Team), 0)
    print("visitor name")
    matrixportal.add_text(
        text_position=(homeTeam_x, team_y),
        text_font=terminalio.FONT,
        text_color=team_Colors[homeTeam_Team].get("team"),
    )
    matrixportal.set_text(str(homeTeam_Team), 1)
    print("homeTeam name")
    matrixportal.add_text(
        text_position=(awayTeam_x, score_y),
        text_font=terminalio.FONT,
        text_color=team_Colors[visitor_Team].get("score"),
    )
    matrixportal.set_text(str(visitor_Points), 2)
    print("visitor score")
    matrixportal.add_text(
        text_position=(homeTeam_x, score_y),
        text_font=terminalio.FONT,
        text_color=team_Colors[homeTeam_Team].get("score"),
    )
    matrixportal.set_text(str(homeTeam_Points), 3)
    print("homeTeam score")

    print("Made it to the bottom")
    json_Data = ""

    # copy relevant information into appropriate variables, including setting colors

    # display information

    # refresh every... minute?  2 minutes?
    time.sleep(15)  # every minute and a half for the time being

Code: Select all

Fetching json from https://api.mysportsfeeds.com/v1.0/pull/nhl/current/scoreboard.json?fordate=20210319
Connecting to AP  
Retrieving data...Traceback (most recent call last):
  File "code.py", line 74, in <module>
  File "adafruit_portalbase/__init__.py", line 365, in fetch
  File "adafruit_portalbase/network.py", line 524, in fetch_data
  File "adafruit_portalbase/network.py", line 535, in _parse_data
  File "adafruit_portalbase/network.py", line 490, in check_response
HttpError: Code 401: Unauthorized
I've poked around the Internet, Adafruit in particular, and just having a hard time getting this to work.

Any help is greatly appreciated,

Scott

Locked
Please be positive and constructive with your questions and comments.

Return to “AdaBox! Show us what you made!”