Scores updates (#826)
* Fix NameError * Change Cleveland Baseball Team to Guardians * Update NBA game clock parsing code to reflect API change
This commit is contained in:
parent
3e9f61dff0
commit
294521e453
@ -114,7 +114,7 @@ class ScoresBackend(SettingsBase):
|
|||||||
suffix = 'th'
|
suffix = 'th'
|
||||||
else:
|
else:
|
||||||
ord_map = {1: 'st', 2: 'nd', 3: 'rd'}
|
ord_map = {1: 'st', 2: 'nd', 3: 'rd'}
|
||||||
suffix = ordmap.get(number % 10, 'th')
|
suffix = ord_map.get(number % 10, 'th')
|
||||||
return f'{number}{suffix}'
|
return f'{number}{suffix}'
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -62,7 +62,7 @@ class MLB(ScoresBackend):
|
|||||||
* **BOS** — Boston Red Sox
|
* **BOS** — Boston Red Sox
|
||||||
* **CHC** — Chicago Cubs
|
* **CHC** — Chicago Cubs
|
||||||
* **CIN** — Cincinnati Reds
|
* **CIN** — Cincinnati Reds
|
||||||
* **CLE** — Cleveland Indians
|
* **CLE** — Cleveland Guardians
|
||||||
* **COL** — Colorado Rockies
|
* **COL** — Colorado Rockies
|
||||||
* **CWS** — Chicago White Sox
|
* **CWS** — Chicago White Sox
|
||||||
* **DET** — Detroit Tigers
|
* **DET** — Detroit Tigers
|
||||||
|
@ -3,6 +3,7 @@ from i3pystatus.scores import ScoresBackend
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
import pytz
|
import pytz
|
||||||
|
import re
|
||||||
import time
|
import time
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
@ -206,12 +207,11 @@ class NBA(ScoresBackend):
|
|||||||
ret['live_url'] = self.live_url.format(id=ret['id'])
|
ret['live_url'] = self.live_url.format(id=ret['id'])
|
||||||
|
|
||||||
status_map = {
|
status_map = {
|
||||||
'1': 'pregame',
|
1: 'pregame',
|
||||||
'2': 'in_progress',
|
2: 'in_progress',
|
||||||
'3': 'final',
|
3: 'final',
|
||||||
}
|
}
|
||||||
period_data = game.get('period_time', {})
|
status_code = int(game.get('gameStatus', 1))
|
||||||
status_code = period_data.get('game_status', '1')
|
|
||||||
status = status_map.get(status_code)
|
status = status_map.get(status_code)
|
||||||
if status is None:
|
if status is None:
|
||||||
self.logger.debug(
|
self.logger.debug(
|
||||||
@ -221,8 +221,8 @@ class NBA(ScoresBackend):
|
|||||||
ret['status'] = status_map[status_code]
|
ret['status'] = status_map[status_code]
|
||||||
|
|
||||||
if ret['status'] in ('in_progress', 'final'):
|
if ret['status'] in ('in_progress', 'final'):
|
||||||
period_number = int(period_data.get('period_value', 1))
|
period_number = int(game.get('period', 1))
|
||||||
total_periods = int(period_data.get('total_periods', 0))
|
total_periods = int(game.get('regulationPeriods', 4))
|
||||||
period_diff = period_number - total_periods
|
period_diff = period_number - total_periods
|
||||||
ret['quarter'] = 'OT' \
|
ret['quarter'] = 'OT' \
|
||||||
if period_diff == 1 \
|
if period_diff == 1 \
|
||||||
@ -231,11 +231,21 @@ class NBA(ScoresBackend):
|
|||||||
else:
|
else:
|
||||||
ret['quarter'] = ''
|
ret['quarter'] = ''
|
||||||
|
|
||||||
ret['time_remaining'] = game.get('game_clock')
|
clock = game.get('gameClock', '')
|
||||||
if ret['time_remaining'] == '':
|
try:
|
||||||
ret['time_remaining'] = 'End'
|
mins, secs = re.match(r'^PT(\d+)M(\d+\.\d)0?S$', clock).groups()
|
||||||
elif ret['time_remaining'] is None:
|
except AttributeError:
|
||||||
ret['time_remaining'] = ''
|
ret['time_remaining'] = ''
|
||||||
|
self.logger.warning('Failed to parse gameClock value: {clock}')
|
||||||
|
else:
|
||||||
|
mins = mins.lstrip('0')
|
||||||
|
if mins:
|
||||||
|
secs = secs.split('.')[0]
|
||||||
|
if not mins and secs == '00.0':
|
||||||
|
ret['time_remaining'] = 'End'
|
||||||
|
else:
|
||||||
|
ret['time_remaining'] = f'{mins}:{secs}'
|
||||||
|
|
||||||
ret['overtime'] = ret['quarter'] if 'OT' in ret['quarter'] else ''
|
ret['overtime'] = ret['quarter'] if 'OT' in ret['quarter'] else ''
|
||||||
|
|
||||||
for key in ('home', 'away'):
|
for key in ('home', 'away'):
|
||||||
|
Loading…
Reference in New Issue
Block a user