Skip to content

Commit

Permalink
#99 less local vars
Browse files Browse the repository at this point in the history
  • Loading branch information
StegSchreck committed Dec 17, 2016
1 parent 5777418 commit c0ecf18
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 33 deletions.
3 changes: 1 addition & 2 deletions core/parsers/match_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def parse_html(self, soup):
matchday_number = soup.find_all('tbody')[2].find_all('b')[0].get_text().split(',')[1].split('.')[0].strip()
matchday, _ = Matchday.objects.get_or_create(season=season, number=matchday_number)

venue = soup.find_all('em')[1].get_text()
match_result = soup.find_all('table')[5].find_all('tr')[0].find_all('td')[3].div.font.get_text()
home_team_score = match_result.split(':')[0]
guest_team_score = match_result.split(':')[1]
Expand Down Expand Up @@ -107,6 +106,6 @@ def parse_html(self, soup):
else:
raise MultipleObjectsReturned('There are multiple games on matchday: {}'.format(matchday))

match.venue = venue
match.venue = soup.find_all('em')[1].get_text()
match.save()
return match
46 changes: 15 additions & 31 deletions core/parsers/player_statistics_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,49 +35,33 @@ def parse_html(self, soup):
def parse_row(self, player_row):
player_stat_values = self._filter_invalid_cells(player_row.find_all('td'))

strength = player_stat_values[4].get_text().strip(' ')
freshness = player_stat_values[5].get_text()
games_in_season = player_stat_values[6].get_text()
goals_in_season = player_stat_values[7].get_text()
won_tacklings_in_season = \
self._get_value_from_multivalue_table_cell(player_stat_values[8], 0)
lost_tacklings_in_season = \
self._get_value_from_multivalue_table_cell(player_stat_values[8], 1)
won_friendly_tacklings_in_season = \
self._get_value_from_multivalue_table_cell(player_stat_values[9], 0)
lost_friendly_tacklings_in_season = \
self._get_value_from_multivalue_table_cell(player_stat_values[9], 1)
yellow_cards_in_season = \
self._get_value_from_multivalue_table_cell(player_stat_values[12], 0)
red_cards_in_season = \
self._get_value_from_multivalue_table_cell(player_stat_values[12], 1)
ep = self._get_ep_tp_value_from_table_cell(player_stat_values[13])
tp = self._get_ep_tp_value_from_table_cell(player_stat_values[14])
awp = player_stat_values[15].span.get_text().replace('.', '')
equity = self._get_equity_value_from_table_cell(player_stat_values[17])

player = self._parse_player(player_stat_values)
won_tacklings_in_season = self._get_value_from_multivalue_table_cell(player_stat_values[8], 0)
lost_tacklings_in_season = self._get_value_from_multivalue_table_cell(player_stat_values[8], 1)
won_friendly_tacklings_in_season = self._get_value_from_multivalue_table_cell(player_stat_values[9], 0)
lost_friendly_tacklings_in_season = self._get_value_from_multivalue_table_cell(player_stat_values[9], 1)
yellow_cards_in_season = self._get_value_from_multivalue_table_cell(player_stat_values[12], 0)
red_cards_in_season = self._get_value_from_multivalue_table_cell(player_stat_values[12], 1)

parsed_player_stat, _ = PlayerStatistics.objects.get_or_create(
matchday=self.matchday,
player=player
player=self._parse_player(player_stat_values)
)
logger.debug('===== PlayerStatistics parsed: %s', parsed_player_stat)

parsed_player_stat.strength = strength
parsed_player_stat.games_in_season = games_in_season
parsed_player_stat.freshness = freshness
parsed_player_stat.goals_in_season = goals_in_season
parsed_player_stat.strength = player_stat_values[4].get_text().strip(' ')
parsed_player_stat.games_in_season = player_stat_values[6].get_text()
parsed_player_stat.freshness = player_stat_values[5].get_text()
parsed_player_stat.goals_in_season = player_stat_values[7].get_text()
parsed_player_stat.won_tacklings_in_season = won_tacklings_in_season
parsed_player_stat.lost_tacklings_in_season = lost_tacklings_in_season
parsed_player_stat.won_friendly_tacklings_in_season = won_friendly_tacklings_in_season
parsed_player_stat.lost_friendly_tacklings_in_season = lost_friendly_tacklings_in_season
parsed_player_stat.yellow_cards_in_season = yellow_cards_in_season
parsed_player_stat.red_cards_in_season = red_cards_in_season
parsed_player_stat.ep = ep
parsed_player_stat.tp = tp
parsed_player_stat.awp = awp
parsed_player_stat.equity = equity
parsed_player_stat.ep = self._get_ep_tp_value_from_table_cell(player_stat_values[13])
parsed_player_stat.tp = self._get_ep_tp_value_from_table_cell(player_stat_values[14])
parsed_player_stat.awp = player_stat_values[15].span.get_text().replace('.', '')
parsed_player_stat.equity = self._get_equity_value_from_table_cell(player_stat_values[17])

parsed_player_stat.save()

Expand Down

0 comments on commit c0ecf18

Please sign in to comment.