Skip to content

Commit

Permalink
#99 remove some unsed locl vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Sh4kE committed Dec 18, 2016
1 parent 6e0855f commit 54cdfb8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion core/parsers/match_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def parse(self):
soup = BeautifulSoup(self.html_source, "html.parser")
return self.parse_html(soup)

def parse_html(self, soup):
def parse_html(self, soup): #pylint: disable=too-many-locals
"""
:param soup: BeautifulSoup of match page
:return: parsed match
Expand Down
33 changes: 22 additions & 11 deletions core/parsers/won_by_default_match_row_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ def parse_html(self, row):
number=row.find_all('td')[0].get_text().replace('\n', '')
)

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

match_result = row.find_all('span', class_='erganz')[0].find_parent('tr').get_text().strip()
home_team_score = match_result.split(':')[0].strip()
guest_team_score = match_result.split(':')[1].strip()
guest_team_score, home_team_score = self._get_team_scores(row)

home_team = row.find_all('td')[1].get_text().strip()
home_team_name = home_team[0:home_team.find('(') - 1]
Expand All @@ -44,10 +40,8 @@ def parse_html(self, row):
guest_team_name = guest_team[0:guest_team.find('(') - 1]
guest_team_strength = guest_team[guest_team.find('(') + 1:guest_team.find(')')]

existing_match = Match.objects.filter(matchday=matchday, user=self.user)

if len(existing_match) == 1:
match = existing_match[0]
if len(self._existing_matches(matchday)) == 1:
match = self._existing_matches(matchday)[0]

match.home_team_statistics.score = home_team_score
match.home_team_statistics.team_name = home_team_name
Expand All @@ -58,7 +52,7 @@ def parse_html(self, row):
match.guest_team_statistics.team_name = guest_team_name
match.guest_team_statistics.strength = guest_team_strength
match.guest_team_statistics.save()
elif len(existing_match) == 0:
elif not self._has_existing_matches(matchday):
home_team_stat = MatchTeamStatistics.objects.create(
score=home_team_score,
team_name=home_team_name,
Expand All @@ -81,11 +75,28 @@ def parse_html(self, row):

match = Match.objects.create(
matchday=matchday,
is_home_match=is_home_match,
is_home_match=self._is_home_match(row),
user=self.user,
home_team_statistics=home_team_stat,
guest_team_statistics=guest_team_stat
)
else:
raise MultipleObjectsReturned('There are multiple games on matchday: {}'.format(matchday))
return match

def _has_existing_matches(self, matchday):
return self._existing_matches(matchday).count() > 0

def _existing_matches(self, matchday):
return Match.objects.filter(matchday=matchday, user=self.user)

@staticmethod
def _get_team_scores(row):
match_result = row.find_all('span', class_='erganz')[0].find_parent('tr').get_text().strip()
home_team_score = match_result.split(':')[0].strip()
guest_team_score = match_result.split(':')[1].strip()
return guest_team_score, home_team_score

@staticmethod
def _is_home_match(row):
return "black" in row.find_all('td')[1].a.get('class')
4 changes: 2 additions & 2 deletions core/tests/unit/views/test_parser_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def test_match_parser_view(self, matchday_parser_mock, match_parser_mock, parse_
@patch('core.managers.parser_manager.ParserManager.parse_all_matches')
@patch('core.managers.parser_manager.ParserManager.parse_awp_boundaries')
@patch('core.managers.parser_manager.ParserManager.parse_ofm_version')
def test_parser_view(self, site_manager_mock, parse_matchday_mock, parse_players_mock, parse_player_statistics_mock,
parse_finances_mock, parse_all_matches_mock, parse_awp_mock, parse_version_mock): # noqa
def test_parser_view(self, site_manager_mock, parse_matchday_mock, parse_players_mock, parse_player_statistics_mock, # pylint: disable=too-many-arguments
parse_finances_mock, parse_all_matches_mock, parse_awp_mock, parse_version_mock):
response = self.client.get(reverse('core:trigger:trigger_parsing'))

self.assertEqual(response.status_code, 302)
Expand Down

0 comments on commit 54cdfb8

Please sign in to comment.