Skip to content

Commit

Permalink
#99 less local variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Sh4kE committed Dec 10, 2016
1 parent cb280ed commit d2817e6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
32 changes: 12 additions & 20 deletions core/parsers/stadium_statistics_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,22 @@ def parse_html(self, soup):
security_row = stadium_items[2]
parking_row = stadium_items[3]

is_light_under_construction = \
light_row.find_all('td')[1].img is not None and 'underconst' in light_row.find_all('td')[1].img['src']
is_screen_under_construction = \
screen_row.find_all('td')[1].img is not None and 'underconst' in screen_row.find_all('td')[1].img['src']
is_security_under_construction = \
security_row.find_all('td')[1].img is not None and 'underconst' in security_row.find_all('td')[1].img['src']
is_parking_under_construction = \
parking_row.find_all('td')[1].img is not None and 'underconst' in parking_row.find_all('td')[1].img['src']

if is_light_under_construction and last_stadium_level:
if StadiumStatisticsParser._is_under_construction(light_row) and last_stadium_level:
light = last_stadium_level.light
else:
light = self._create_stadium_level_item_from_row(light_row)

if is_screen_under_construction and last_stadium_level:
if StadiumStatisticsParser._is_under_construction(screen_row) and last_stadium_level:
screen = last_stadium_level.screen
else:
screen = self._create_stadium_level_item_from_row(screen_row)

if is_security_under_construction and last_stadium_level:
if StadiumStatisticsParser._is_under_construction(security_row) and last_stadium_level:
security = last_stadium_level.security
else:
security = self._create_stadium_level_item_from_row(security_row)

if is_parking_under_construction and last_stadium_level:
if StadiumStatisticsParser._is_under_construction(parking_row) and last_stadium_level:
parking = last_stadium_level.parking
else:
parking = self._create_stadium_level_item_from_row(parking_row)
Expand All @@ -84,15 +75,16 @@ def parse_html(self, soup):

return match_stadium_stat

def _create_stadium_level_item_from_row(self, row):
level = row.find_all('td')[2].span.get_text()
value = self.strip_euro_sign(row.find_all('td')[4].span.get_text().replace('.', '').strip())
daily_costs = self.strip_euro_sign(row.find_all('td')[5].span.get_text().replace('.', '').strip())
@staticmethod
def _is_under_construction(stadium_attribute):
return stadium_attribute.find_all('td')[1].img is not None and \
'underconst' in stadium_attribute.find_all('td')[1].img['src']

def _create_stadium_level_item_from_row(self, row):
stadium_level_item, _ = StadiumLevelItem.objects.get_or_create(
current_level=level,
value=value,
daily_costs=daily_costs
current_level=row.find_all('td')[2].span.get_text(),
value=self.strip_euro_sign(row.find_all('td')[4].span.get_text().replace('.', '').strip()),
daily_costs=self.strip_euro_sign(row.find_all('td')[5].span.get_text().replace('.', '').strip())
)

return stadium_level_item
7 changes: 4 additions & 3 deletions core/parsers/won_by_default_match_row_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ def parse_html(self, row):
"""

# we assume to have parsed the season beforehand (with the matchday)
season = Matchday.objects.all()[0].season
matchday_number = row.find_all('td')[0].get_text().replace('\n', '')
matchday, _ = Matchday.objects.get_or_create(season=season, number=matchday_number)
matchday, _ = Matchday.objects.get_or_create(
season=Matchday.objects.all()[0].season,
number=row.find_all('td')[0].get_text().replace('\n', '')
)

is_home_match = "black" in row.find_all('td')[1].a.get('class')

Expand Down

0 comments on commit d2817e6

Please sign in to comment.