Skip to content

Commit

Permalink
#99 refactor out stadium item parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sh4kE committed Dec 12, 2016
1 parent 6596ab7 commit 3167bb8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions core/parsers/stadium_statistics_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,11 @@ def parse_html(self, soup):
last_stadium_level = None
if last_home_matches.count() > 0:
# only consider matches statistics BEFORE current match
last_home_matches = [match for match in last_home_matches if
match.matchday.number <= self.match.matchday.number]
last_home_match = last_home_matches[0]
last_home_match = [match for match in last_home_matches if
match.matchday.number <= self.match.matchday.number][0]
last_stadium_level = MatchStadiumStatistics.objects.filter(match=last_home_match)[0].level

stadium_items = soup.find('table', id='stadiumExtra').tbody.find_all('tr')
light_row = stadium_items[0]
screen_row = stadium_items[1]
security_row = stadium_items[2]
parking_row = stadium_items[3]
light_row, screen_row, security_row, parking_row = self._get_stadium_items(soup)

if self._is_under_construction(light_row) and last_stadium_level:
light = last_stadium_level.light
Expand Down Expand Up @@ -75,6 +70,11 @@ def parse_html(self, soup):

return match_stadium_stat

@staticmethod
def _get_stadium_items(soup):
items = soup.find('table', id='stadiumExtra').tbody.find_all('tr')
return items[0], items[1], items[2], items[3]

@staticmethod
def _is_under_construction(stadium_attribute):
return stadium_attribute.find_all('td')[1].img is not None and \
Expand Down

0 comments on commit 3167bb8

Please sign in to comment.