Beispiel #1
0
 def teams(self) -> List[Team]:
     try:
         if not self._teams:
             self._teams = []
             json_data = get_json(
                 f'{self.baseUrl}/teams?groups={self.conferenceID}&limit=1000'
             )
             for team in helpers.get_nested_dict_value(
                     dictionary=json_data,
                     ordered_list_of_keys=[
                         'sports', 0, 'leagues', 0, 'teams'
                     ],
                     default_value=[]):
                 new_team = Team(team_id=helpers.get_nested_dict_value(
                     dictionary=team, ordered_list_of_keys=['team', 'id']),
                                 data={
                                     'league': self.league,
                                     'sport': self.sport,
                                     'base_url': self.baseUrl,
                                     'teamNickname': None
                                 })
                 self._teams.append(new_team)
         return self._teams
     except Exception as e:
         print(e)
     return []
Beispiel #2
0
 def odds(self) -> dict:
     try:
         if not self.spread or not self.overUnder:
             json_data = self.get_json()
             if json_data.get('pickcenter'):
                 self.spread = helpers.get_nested_dict_value(
                     dictionary=json_data,
                     ordered_list_of_keys=['pickcenter', 0, 'details'])
                 self.overUnder = helpers.get_nested_dict_value(
                     dictionary=json_data,
                     ordered_list_of_keys=['pickcenter', 0, 'overUnder'])
         return {'spread': self.spread, 'overUnder': self.overUnder}
     except Exception as e:
         print(e)
     return {}
Beispiel #3
0
 def score(self) -> dict:
     try:
         json_data = self.get_json()
         if json_data.get('scoringPlays'):
             last_score = helpers.get_nested_dict_value(
                 dictionary=json_data,
                 ordered_list_of_keys=['scoringPlays', -1])
             if last_score:
                 return {
                     'awayScore': last_score.get('awayScore', 0),
                     'homeScore': last_score.get('homeScore', 0)
                 }
     except Exception as e:
         print(e)
     return {'awayScore': 0, 'homeScore': 0}
Beispiel #4
0
 def teams(self) -> dict:
     if not self._homeTeam and not self._awayTeam:
         json_data = self.get_json()
         teams = helpers.get_nested_dict_value(
             dictionary=json_data,
             ordered_list_of_keys=['boxscore', 'teams'])
         if teams:
             self._awayTeam = Team(team_id=helpers.get_nested_dict_value(
                 dictionary=teams, ordered_list_of_keys=[0, 'team', 'id']),
                                   data={
                                       'league': self.league,
                                       'sport': self.sport,
                                       'base_url': self.baseUrl,
                                       'teamNickname': None
                                   })
             self._homeTeam = Team(team_id=helpers.get_nested_dict_value(
                 dictionary=teams, ordered_list_of_keys=[1, 'team', 'id']),
                                   data={
                                       'league': self.league,
                                       'sport': self.sport,
                                       'base_url': self.baseUrl,
                                       'teamNickname': None
                                   })
     return {'awayTeam': self._awayTeam, 'homeTeam': self._homeTeam}
Beispiel #5
0
 def conference(self):
     try:
         if not self._conference:
             json_data = self.get_json()
             self._conference = Conference(
                 conference_id=helpers.get_nested_dict_value(
                     dictionary=json_data,
                     ordered_list_of_keys=['team', 'groups', 'id']),
                 data={
                     'league': self.league,
                     'sport': self.sport,
                     'base_url': self.baseUrl
                 })
         return self._conference
     except Exception as e:
         print(e)
     return None
Beispiel #6
0
 def current_games(self) -> List[Game]:
     try:
         self._currentGames = []
         json_data = get_json(f'{self.baseUrl}/scoreboard')
         for game in helpers.get_nested_dict_value(
                 dictionary=json_data,
                 ordered_list_of_keys=['events'],
                 default_value=[]):
             new_game = Game(game_id=game.get('id'),
                             data={
                                 'league': self.league,
                                 'sport': self.sport,
                                 'base_url': self.baseUrl
                             })
             self._currentGames.append(new_game)
         return self._currentGames
     except Exception as e:
         print(e)
     return []
Beispiel #7
0
 def _make_game(self):
     try:
         json_data = self.get_json()
         if json_data:
             self.venue = {
                 'name':
                 helpers.get_nested_dict_value(
                     dictionary=json_data,
                     ordered_list_of_keys=['gameInfo', 'venue',
                                           'fullName']),
                 'city':
                 helpers.get_nested_dict_value(dictionary=json_data,
                                               ordered_list_of_keys=[
                                                   'gameInfo', 'venue',
                                                   'address', 'city'
                                               ]),
                 'state':
                 helpers.get_nested_dict_value(dictionary=json_data,
                                               ordered_list_of_keys=[
                                                   'gameInfo', 'venue',
                                                   'address', 'state'
                                               ]),
                 'capacity':
                 helpers.get_nested_dict_value(
                     dictionary=json_data,
                     ordered_list_of_keys=['gameInfo', 'venue',
                                           'capacity']),
                 'image':
                 (helpers.get_nested_dict_value(dictionary=json_data,
                                                ordered_list_of_keys=[
                                                    'gameInfo', 'venue',
                                                    'images', 0, 'href'
                                                ]))
             }
             self.attendance = (helpers.get_nested_dict_value(
                 dictionary=json_data,
                 ordered_list_of_keys=['gameInfo', 'venue', 'attendance']))
             self.broadcast = (helpers.get_nested_dict_value(
                 dictionary=json_data,
                 ordered_list_of_keys=[
                     'header', 'competitions', 0, 'broadcasts', 0, 'media',
                     'shortName'
                 ]))
     except Exception as e:
         print(e)
Beispiel #8
0
 def update_player_info(self) -> bool:
     try:
         json_data = self.get_json()
         if not json_data:
             return False
         if json_data.get('athlete'):
             json_data = json_data['athlete']
         try:
             self.firstName = json_data.get('firstName')
             self.lastName = json_data.get('lastName')
             self.jerseyNumber = json_data.get('jersey')
             self.position = helpers.get_nested_dict_value(
                 dictionary=json_data,
                 ordered_list_of_keys=['position', 'abbreviation'])
             return True
         except Exception as e:
             print(f'Error in inner try: {e}')
     except Exception as e:
         print(f'Error in outer try: {e}')
     return False
Beispiel #9
0
 def team(self):
     if not self._team:
         json_data = self.get_json()
         if json_data and helpers.nested_key_exist(
                 dictionary=json_data,
                 ordered_list_of_keys=['athlete', 'team']):
             self._team = Team(
                 team_id=helpers.get_nested_dict_value(
                     dictionary=json_data,
                     ordered_list_of_keys=['athlete', 'team', 'id']),
                 data={
                     'teamNickname':
                     None,
                     'league':
                     self.league,
                     'sport':
                     self.sport,
                     'base_url':
                     f'http://site.api.espn.com/apis/site/v2/sports/{self.sport}/{self.league}'
                 })
     return self._team
Beispiel #10
0
 def probability(self) -> dict:
     try:
         json_data = self.get_json()
         if json_data.get('winprobability'):
             last_probability = helpers.get_nested_dict_value(
                 dictionary=json_data,
                 ordered_list_of_keys=['winprobability', -1])
             if last_probability and last_probability.get(
                     'homeWinPercentage'):
                 if last_probability['homeWinPercentage'] < 0.5:
                     percentage = (1 - int(
                         last_probability['homeWinPercentage'])) * 100
                     winning_team = self.awayTeam
                 else:
                     percentage = int(
                         last_probability['homeWinPercentage']) * 100
                     winning_team = self.homeTeam
                 return {
                     'winningTeam': winning_team,
                     'percentage': percentage,
                 }
     except Exception as e:
         print(e)
     return {}
Beispiel #11
0
 def stats_summary(self) -> Union[dict, None]:
     json_data = self.get_json()
     return helpers.get_nested_dict_value(
         dictionary=json_data,
         ordered_list_of_keys=['athlete', 'statsSummary'])
Beispiel #12
0
 def _make_team(self):
     try:
         json_data = self.get_json()
         if json_data.get('team'):
             self.nickname = helpers.get_nested_dict_value(
                 dictionary=json_data,
                 ordered_list_of_keys=['team', 'nickname'])
             self.abbreviation = helpers.get_nested_dict_value(
                 dictionary=json_data,
                 ordered_list_of_keys=['team', 'abbreviation'])
             self.location = helpers.get_nested_dict_value(
                 dictionary=json_data,
                 ordered_list_of_keys=['team', 'location'])
             self.mascot = helpers.get_nested_dict_value(
                 dictionary=json_data,
                 ordered_list_of_keys=['team', 'name'])
             self.displayName = helpers.get_nested_dict_value(
                 dictionary=json_data,
                 ordered_list_of_keys=['team', 'displayName'])
             self.color = helpers.get_nested_dict_value(
                 dictionary=json_data,
                 ordered_list_of_keys=['team', 'color'])
             self.teamLogoURL = helpers.get_nested_dict_value(
                 dictionary=json_data,
                 ordered_list_of_keys=['team', 'logos', 0, 'href'])
             self.record = {
                 'wins':
                 helpers.get_nested_dict_value(dictionary=json_data,
                                               ordered_list_of_keys=[
                                                   'team', 'record',
                                                   'items', 0, 'stats', 1,
                                                   'value'
                                               ]),
                 'losses':
                 helpers.get_nested_dict_value(dictionary=json_data,
                                               ordered_list_of_keys=[
                                                   'team', 'record',
                                                   'items', 0, 'stats', 2,
                                                   'value'
                                               ]),
                 'ties':
                 helpers.get_nested_dict_value(dictionary=json_data,
                                               ordered_list_of_keys=[
                                                   'team', 'record',
                                                   'items', 0, 'stats', 5,
                                                   'value'
                                               ])
             }
             self.statistics = helpers.get_nested_dict_value(
                 dictionary=json_data,
                 ordered_list_of_keys=['team', 'record', 'items']),
             self.links = helpers.get_nested_dict_value(
                 dictionary=json_data,
                 ordered_list_of_keys=['team', 'links'])
     except Exception as e:
         print(e)