Skip to content

Commit

Permalink
Fix issue pulling football league positions
Browse files Browse the repository at this point in the history
Occasionally, a team's league position will not be posted on their team
page, throwing an error while attempting to parse that information.
Defaulting the value to None in this scenario will skip the error while
allowing expected functionality to continue.

Signed-Off-By: Robert Clark <robdclark@outlook.com>
  • Loading branch information
roclark committed Nov 13, 2020
1 parent 9b6039f commit 20d3ec0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 5 additions & 2 deletions sportsreference/fb/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,15 @@ def _records(self, record_line):
records = record_line.lower().replace('record: ', '')
records_split = records.split(',')
if len(records_split) != 3:
return None, None, None
return None, None, None, None
record, points, position = records_split
points = re.sub(' point.*', '', points).strip()
position = re.sub(r'\(.*\)', '', position).strip()
league = re.sub('.* in ', '', position).title()
position = re.findall(r'\d+', position)[0]
try:
position = re.findall(r'\d+', position)[0]
except IndexError:
position = None
return record, points, position, league

def _goals(self, goals_line):
Expand Down
9 changes: 8 additions & 1 deletion tests/unit/test_fb_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ def test_records_missing_result(self):

output = self.team._records(html)

assert output == (None, None, None)
assert output == (None, None, None, None)

def test_records_missing_position(self):
html = 'Record: 5-0-0, 15 points (3.0 per game), Premier League'

output = self.team._records(html)

assert output == ('5-0-0', '15', None, 'Premier League')

def test_goals_missing(self):
html = 'Goals: 20 (2.5 per game), Goals Against: 11 (1.38 per game)'
Expand Down

0 comments on commit 20d3ec0

Please sign in to comment.