Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List favorite team's game(s) first #43

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- handle missing flags for postponements
- added setting for auto selecting a stream (favorite/home)
- added context menu item for choosing stream manually
- list favorite team's game(s) first
</news>
<language>en</language>
<platform>all</platform>
Expand Down
24 changes: 20 additions & 4 deletions resources/lib/mlb.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ def todays_games(game_day):

addPlaylist(date_display, str(game_day), 900, ICON, FANART)

if ONLY_FREE_GAMES != 'true':
create_big_inning_listitem(game_day)

#url = 'http://gdx.mlb.com/components/game/mlb/' + url_game_day + '/grid_ce.json'
url = API_URL + '/api/v1/schedule'
# url += '?hydrate=broadcasts(all),game(content(all)),probablePitcher,linescore,team,flags'
Expand All @@ -44,8 +41,27 @@ def todays_games(game_day):
r = requests.get(url,headers=headers, verify=VERIFY)
json_source = r.json()

favorite_games = []
remaining_games = []

for game in json_source['dates'][0]['games']:
if getFavTeamId() in {str(game['teams']['home']['team']['id']),
str(game['teams']['away']['team']['id'])}:
favorite_games.append(game)
else:
remaining_games.append(game)

try:
for game in favorite_games:
create_game_listitem(game, game_day)
except:
pass

if ONLY_FREE_GAMES != 'true':
create_big_inning_listitem(game_day)

try:
for game in json_source['dates'][0]['games']:
for game in remaining_games:
create_game_listitem(game, game_day)
except:
pass
Expand Down