Skip to content

Commit

Permalink
added __str__ and __repr__ methods for Match
Browse files Browse the repository at this point in the history
  • Loading branch information
dwillis committed Jun 25, 2020
1 parent f644e33 commit 4f3bde8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
38 changes: 22 additions & 16 deletions espncricinfo/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ def __init__(self, match_id):
self.close_of_play = self._close_of_play()


def __str__(self):
return self.description

def __repr__(self):
return (f'{self.__class__.__name__}('f'{self.match_id!r})')

def get_json(self):
r = requests.get(self.json_url)
if r.status_code == 404:
Expand Down Expand Up @@ -381,51 +387,51 @@ def _toss_winner_team_id(self):
# comms_json methods

def _rosters(self):
if self.comms_json:
try:
return self.comms_json['props']['pageProps']['data']['content']['teams']
else:
except:
return None

def _all_innings(self):
if self.comms_json:
try:
return self.comms_json['props']['pageProps']['data']['content']['innings']
else:
except:
return None

def _close_of_play(self):
if self.comms_json:
try:
return self.comms_json['props']['pageProps']['data']['content']['closePlay']
else:
except:
return None

def batsmen(self, innings):
if self.comms_json:
try:
return self.comms_json['props']['pageProps']['data']['content']['innings'][str(innings)]['batsmen']
else:
except:
return None

def bowlers(self, innings):
if self.comms_json:
try:
return self.comms_json['props']['pageProps']['data']['content']['innings'][str(innings)]['bowlers']
else:
except:
return None

def did_not_bat(self, innings):
if self.comms_json:
try:
return self.comms_json['props']['pageProps']['data']['content']['innings'][str(innings)]['didNotBat']
else:
except:
return None

def extras(self, innings):
if self.comms_json:
try:
return self.comms_json['props']['pageProps']['data']['content']['innings'][str(innings)]['extras']
else:
except:
return None

def fows(self, innings):
if self.comms_json:
try:
return self.comms_json['props']['pageProps']['data']['content']['innings'][str(innings)]['fallOfWickets']
else:
except:
return None

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions espncricinfo/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ def get_html(self):
else:
return BeautifulSoup(r.text, 'html.parser')

def json(self):
def summary_json(self):
try:
text = self.html.find_all('script')[13].contents[0]
return json.loads(text)
except:
return None

def _match_ids(self):
matches = [x['id'] for x in self.json['props']['pageProps']['data']['content']['leagueEvents'][0]['matchEvents']]
matches = [x['id'] for x in self.summary_json()['props']['pageProps']['data']['content']['leagueEvents'][0]['matchEvents']]
return matches

def _build_matches(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
long_description = fh.read()

setup(name="python-espncricinfo",
version="0.5.6",
version="0.5.7",
description="ESPNCricInfo API client",
license="MIT",
install_requires=["requests", "bs4", "dateparser"],
Expand Down

0 comments on commit 4f3bde8

Please sign in to comment.