Skip to content

Commit 9ed433b

Browse files
authored
Merge pull request #77 from TheFinalJoke/dev
Update to 1.1.0
2 parents c24f64f + c561351 commit 9ed433b

File tree

7 files changed

+41
-28
lines changed

7 files changed

+41
-28
lines changed

lib/binary_build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
VERSION="1.0.0"
2+
VERSION="1.1.0"
33

44
# Can't put full folders
55
echo "Building the binary"

lib/sports/baseball/baseball.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def url_builder(self, args):
2828
return urls
2929

3030
async def run(self):
31-
self.logger.info('Running baseball API')
31+
self.logger.info('Running Baseball API')
3232
parsed = self.parse_args()
3333
api_data = {}
3434
for section, url in self.url_builder(parsed).items():

lib/sports/hockey/hockey.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ def url_builder(self, args):
2424
urls = {}
2525
base = "https://v1.hockey.api-sports.io/"
2626
if 'standings' in args:
27-
urls.update({'standings': base + f'standings?league=57&season=2020'})
27+
urls.update({'standings': base + f'standings?league=57&season=2021'})
2828
if 'next_game' in args:
2929
urls.update({'next_game': base + f"games?team={self.config.getint('team_id')}&league=57&season=2020&timezone=America/Chicago"})
3030
return urls
3131

3232
async def run(self):
33-
self.logger.info('Running baseball API')
33+
self.logger.info('Running Hockey API')
3434
parsed = self.parse_args()
3535
api_data = {}
3636
for section, url in self.url_builder(parsed).items():

lib/sports/sports.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,27 @@ def __init__(self, api) -> None:
5959
self.full_sport = self.api['Sport']
6060
self.sport = [*self.full_sport]
6161
self.main_sport = self.full_sport[self.sport[0]]
62-
if 'standings' in self.main_sport:
63-
self.standings = self.build_standings()
64-
self._length = len(self.standings)
65-
self._positions = [(team.get('name'), team.get('position')) for team in self.standings]
66-
self._leagues = [(team.get('name'), team.get('league')) for team in self.standings]
67-
self._games_played = [(team.get('name'), team.get('games').get('played')) for team in self.standings]
68-
self._wins = [(team.get('name'), team['games']['win']['total']) for team in self.standings]
69-
self._wins_percentage = [(team.get('name'), team['games']['win']['percentage']) for team in self.standings]
70-
self._losses = [(team.get('name'), team['games']['lose']['total']) for team in self.standings]
71-
self._loss_percentage = [(team.get('name'), team['games']['lose']['percentage']) for team in self.standings]
72-
if 'next_game' in self.main_sport:
73-
self.next_game = self.build_nextgame()
74-
self._game_ids = [game.get('game_id') for game in self.next_game]
75-
self._timestamps = [(game.get('game_id'), game.get('timestamp')) for game in self.next_game]
76-
self._teams = [(game.get('game_id'), game.get('teams')) for game in self.next_game]
77-
self._vs = [(game.get('game_id'), (game['teams']['home']['name'], game['teams']['away']['name'])) for game in self.next_game]
78-
self._status = [(game.get('game_id'), game.get('status')) for game in self.next_game]
79-
self._game_result = {game.get('game_id'): game.get('score') for game in self.next_game}
62+
if len(self.main_sport['standings']['errors']) != 0:
63+
self._error = self.get_error
64+
else:
65+
if 'standings' in self.main_sport:
66+
self.standings = self.build_standings()
67+
self._length = len(self.standings)
68+
self._positions = [(team.get('name'), team.get('position')) for team in self.standings]
69+
self._leagues = [(team.get('name'), team.get('league')) for team in self.standings]
70+
self._games_played = [(team.get('name'), team.get('games').get('played')) for team in self.standings]
71+
self._wins = [(team.get('name'), team['games']['win']['total']) for team in self.standings]
72+
self._wins_percentage = [(team.get('name'), team['games']['win']['percentage']) for team in self.standings]
73+
self._losses = [(team.get('name'), team['games']['lose']['total']) for team in self.standings]
74+
self._loss_percentage = [(team.get('name'), team['games']['lose']['percentage']) for team in self.standings]
75+
if 'next_game' in self.main_sport:
76+
self.next_game = self.build_nextgame()
77+
self._game_ids = [game.get('game_id') for game in self.next_game]
78+
self._timestamps = [(game.get('game_id'), game.get('timestamp')) for game in self.next_game]
79+
self._teams = [(game.get('game_id'), game.get('teams')) for game in self.next_game]
80+
self._vs = [(game.get('game_id'), (game['teams']['home']['name'], game['teams']['away']['name'])) for game in self.next_game]
81+
self._status = [(game.get('game_id'), game.get('status')) for game in self.next_game]
82+
self._game_result = {game.get('game_id'): game.get('score') for game in self.next_game}
8083
def __repr__(self):
8184
attrs = [
8285
f"length={self._length}",
@@ -96,7 +99,7 @@ def __repr__(self):
9699
]
97100
joined = "\t\n".join(attrs)
98101
return f"Sport(\n{joined})"
99-
102+
100103
def build_standings(self):
101104
#counter = 0
102105
position = []
@@ -129,6 +132,13 @@ def build_nextgame(self):
129132
})
130133
return main
131134

135+
@property
136+
def get_error(self):
137+
if isinstance(self.main_sport['standings']['errors'], list):
138+
return True, ""
139+
else:
140+
return False, self.main_sport['standings']['errors']['requests']
141+
132142
@property
133143
def get_length_position_teams(self):
134144
return len(self.standings)

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
logger.addHandler(filehandler)
3333

3434
def __version__():
35-
return "1.0.0"
35+
return "1.1.0"
3636
class OledExecption(Exception):
3737
pass
3838
class Main():

matrix/sport/sportmatrix.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def build_top_image(self, api: Dict, xpos: int) -> Tuple:
158158
return master_top_image, (0,0)
159159

160160
def build_standings_image(self, api, xpos) -> Tuple[int, int]:
161-
""",
161+
"""
162162
This is most bottom Image
163163
"""
164164
standings_image = Image.new("RGB", (64,8))
@@ -181,7 +181,9 @@ async def render(self, api, loop):
181181
try:
182182
self.clear()
183183
self.reload_image()
184-
if 'baseball'in api.sport:
184+
if not api.get_error[0]:
185+
raise Exception(api.get_error)
186+
if 'baseball' in api.sport:
185187
# Check Data if Offseason if yes Diplay Offseason, Otherwise Display Data
186188
# Check data if Game is active, if yes Display game -> Score Inning AT bat Maybe?
187189
# Else Display next game
@@ -266,6 +268,7 @@ async def render(self, api, loop):
266268
self.draw_multiline_text((0, 0), "Hockey\nOffseason", font=font)
267269
await self.render_image()
268270
time.sleep(30)
269-
except Exception:
271+
except Exception as e:
272+
self.logger.error(e)
270273
error_matrix = ErrorMatrix(self.matrix, self.logger, "Sports Matrix")
271274
await error_matrix.render()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="ohmyoled",
5-
version="1.0.0",
5+
version="1.1.0",
66
python_requires='<3.9.0',
77
packages=find_packages(),
88
description="64x32 Oled Matrix Display",

0 commit comments

Comments
 (0)