Skip to content

Commit

Permalink
add AssertionError messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-thompson committed Dec 7, 2024
1 parent 4d6110a commit b602ab1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/sportify/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def main():
selected_league = leagues[entry]

teams = [MENU_DATA[league] for league in leagues if league == selected_league]
assert teams != []
assert teams != [], "INVALID TEAM"

submenu = Menu(teams[0], title = "TEAM", clear_screen = True)
entry = submenu.show()
Expand All @@ -22,8 +22,9 @@ def main():
raise SystemExit(EXIT_FAIL)
except TypeError: # occurs when user presses Escape or Q to quit
raise SystemExit(EXIT_OK)
except AssertionError: # impossible
print(UNEXPECTED)
except AssertionError as error: # impossible
print(f"{UNEXPECTED}: {error}")
print(REPORT)
raise SystemExit(EXIT_FAIL)

output(data)
Expand Down
3 changes: 1 addition & 2 deletions src/sportify/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
PROJECT_URL = f"https://github.com/jacob-thompson/{PROJECT}"
API_URL = "https://site.api.espn.com/apis/site/v2/sports/"

ERR = "ERROR:"
REPORT = f"PLEASE SUBMIT AN ISSUE REPORT:\n\t{PROJECT_URL}/issues"
UNEXPECTED = f"{ERR} AN UNEXPECTED ERROR HAS OCCURRED\n{REPORT}"
UNEXPECTED = f"AN UNEXPECTED ERROR HAS OCCURRED"

SPORTS = {
"football": {
Expand Down
4 changes: 2 additions & 2 deletions src/sportify/sportify.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ def output(data):
def request_data(league, team):
try:
sport = [listed for listed, associations in SPORTS.items() if league in associations]
assert sport != []
assert sport != [], "INVALID SPORT"

endpoint = f"{sport[0]}/{league}/teams/{team}/"
response = requests.get(API_URL + endpoint.lower())

if response.status_code == API_OK:
return response.json()
else:
raise BadAPIRequest(f"{ERR} API RESPONSE STATUS CODE {response.status_code}")
raise BadAPIRequest(f"ERROR: API RESPONSE STATUS CODE {response.status_code}")
except requests.exceptions.RequestException as error:
# treat this case as unexpected since RequestException is "ambiguous"
# https://requests.readthedocs.io/en/latest/api/#requests.RequestException
Expand Down

0 comments on commit b602ab1

Please sign in to comment.