outside-edge / python-espncricinfo

Python wrapper for the ESPNCricInfo JSON API
MIT License
144 stars 65 forks source link

New player endpoint for major_teams #62

Closed JackMa222 closed 6 months ago

JackMa222 commented 6 months ago

Player Object Update - Major Teams (_major_teams)

This attempts to fix issue [BUG] Player class is not working with Python 3.11.0 #59

The ESPN Cricinfo html page has been updated with class and syntax changes which mean the previous _major_teams function did not work:

def _major_teams(self):
        return [x.text for x in self.parsed_html.find('div', class_='overview-teams-grid').find_all('h5')]

There is a new endpoint which the ESPN Cricinfo page appears to utilise for player data (or in conjunction with the previous). Example: (https://hs-consumer-api.espncricinfo.com/v1/pages/player/home?playerId=7069)

This provides similar data to the previous endpoint, however there are some differences. For this reason I have only modified the major_teams function with this in order to get it functional (with which the rest are).

def _major_teams(self):
        return [x['team']['longName'] for x in self.new_json['content']['teams']]

Eventually it would most likely be wise to update the rest of the functions to the latest 'endpoint' but for now this fixes previous problems.

dwillis commented 6 months ago

Thank you!