Skip to content

Commit 5d71550

Browse files
committed
#99 fixed some staticmethods
1 parent d1d8378 commit 5d71550

File tree

6 files changed

+37
-36
lines changed

6 files changed

+37
-36
lines changed

core/managers/parser_manager.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ def reset_parsing_flags(self):
3333
self.parsed_matchday = None
3434
self.players_already_parsed = False
3535

36-
def parse_ofm_version(self, site_manager):
36+
@staticmethod
37+
def parse_ofm_version(site_manager):
3738
site_manager.jump_to_frame(Constants.GitHub.LATEST_RELEASE)
3839
version_parser = OfmHelperVersionParser(site_manager.browser.page_source)
3940
return version_parser.parse()
4041

41-
def parse_matchday(self, request, site_manager):
42+
@staticmethod
43+
def parse_matchday(request, site_manager):
4244
site_manager.jump_to_frame(Constants.HEAD)
4345
matchday_parser = MatchdayParser(site_manager.browser.page_source)
4446
return matchday_parser.parse()
@@ -108,7 +110,8 @@ def _parse_single_match(self, request, site_manager, row):
108110
else:
109111
return WonByDefaultMatchRowParser(row, request.user).parse()
110112

111-
def _parse_stadium_statistics(self, request, site_manager, match):
113+
@staticmethod
114+
def _parse_stadium_statistics(request, site_manager, match):
112115
site_manager.jump_to_frame(Constants.Stadium.ENVIRONMENT)
113116
stadium_statistics_parser = StadiumStatisticsParser(site_manager.browser.page_source, request.user, match)
114117
stadium_statistics_parser.parse()

core/ofm_views.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ def get(self, request, *args, **kwargs):
3939
contracts = Contract.objects.filter(user=self.request.user, sold_on_matchday=None)
4040
players = [contract.player for contract in contracts]
4141
current_matchday = Matchday.objects.all()[0]
42-
current_season = current_matchday.season
4342

44-
newer_matchday_season = self.request.GET.get('newer_matchday_season', default=current_season.number)
43+
newer_matchday_season = self.request.GET.get('newer_matchday_season', default=current_matchday.season.number)
4544
newer_matchday = self.request.GET.get('newer_matchday', default=current_matchday.number)
4645
older_matchday_season = self.request.GET.get('older_matchday_season')
4746
older_matchday = self.request.GET.get('older_matchday')
@@ -60,11 +59,12 @@ def get(self, request, *args, **kwargs):
6059
player_statistics_json = [
6160
self._get_player_statistics_diff_in_json(newer_player_statistics, older_player_statistics)
6261
for (newer_player_statistics, older_player_statistics) in player_statistics_tuples
63-
]
62+
]
6463

6564
return self.render_json_response(player_statistics_json)
6665

67-
def _get_statistics_from_player_and_matchday(self, player,
66+
@staticmethod
67+
def _get_statistics_from_player_and_matchday(player,
6868
newer_matchday_season, newer_matchday,
6969
older_matchday_season, older_matchday):
7070

@@ -90,7 +90,8 @@ def _get_statistics_from_player_and_matchday(self, player,
9090

9191
return newer_player_statistics, older_player_statistics
9292

93-
def _get_player_statistics_diff_in_json(self, newer_player_statistics, older_player_statistics):
93+
@staticmethod
94+
def _get_player_statistics_diff_in_json(newer_player_statistics, older_player_statistics):
9495
"""
9596
Args:
9697
newer_player_statistics: newer statistic
@@ -245,12 +246,9 @@ def get(self, request, *args, **kwargs):
245246

246247
return self.render_json_response(finances_json)
247248

248-
def _get_finances_diff_in_json(self, newer_finances, older_finances):
249+
@staticmethod
250+
def _get_finances_diff_in_json(newer_finances, older_finances):
249251
"""
250-
Args:
251-
newer_finances: newer finances
252-
older_finances: older finances
253-
254252
Returns:
255253
A dictionary of finance data. If older_finances is None newer_finances is returned
256254
"""
@@ -430,7 +428,7 @@ def get(self, request, *args, **kwargs):
430428
income_betting.append(data_source[0].income_betting)
431429
matchdays.append(data_source[0].matchday.number)
432430

433-
for idx, entry in enumerate(data_source):
431+
for idx, _ in enumerate(data_source):
434432
if idx + 1 < data_source.count():
435433
income_visitors_league.append(
436434
data_source[idx + 1].income_visitors_league - data_source[idx].income_visitors_league)
@@ -508,7 +506,7 @@ def get(self, request, *args, **kwargs):
508506
expenses_betting.append(-data_source[0].expenses_betting)
509507
matchdays.append(data_source[0].matchday.number)
510508

511-
for idx, entry in enumerate(data_source):
509+
for idx, _ in enumerate(data_source):
512510
if idx + 1 < data_source.count():
513511
expenses_player_salaries.append(
514512
data_source[idx].expenses_player_salaries - data_source[idx + 1].expenses_player_salaries)
@@ -580,11 +578,9 @@ def get(self, request, *args, **kwargs):
580578

581579
return self.render_json_response(match_json)
582580

583-
def _get_match_in_json(self, match):
581+
@staticmethod
582+
def _get_match_in_json(match):
584583
"""
585-
Args:
586-
match: Match
587-
588584
Returns:
589585
A dictionary of match data.
590586
"""
@@ -746,11 +742,9 @@ def get(self, request, *args, **kwargs):
746742

747743
return self.render_json_response(stadium_statistics_json)
748744

749-
def _get_stadium_statistics_in_json(self, stadium_stat):
745+
@staticmethod
746+
def _get_stadium_statistics_in_json(stadium_stat):
750747
"""
751-
Args:
752-
stadium_stat: MatchStadiumStatistics
753-
754748
Returns:
755749
A dictionary of stadium statistics data.
756750
"""

core/parsers/base_parser.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ def __init__(self):
1111
def parse(self):
1212
raise NotImplementedError("Should have implemented this")
1313

14-
def _filter_invalid_cells(self, table_cells):
14+
@staticmethod
15+
def _filter_invalid_cells(table_cells):
1516
import re
1617
counter_cell_pattern = re.compile(r'<td>[0-9]+</td>')
1718
return [cell for cell in table_cells
1819
if str(cell).replace(' ', '').replace('\t', '').replace('\n', '') != '<td>??</td>' and not
1920
counter_cell_pattern.match(str(cell))]
2021

21-
def strip_euro_sign(self, money):
22+
@staticmethod
23+
def strip_euro_sign(money):
2224
return money[:-2]

core/parsers/player_statistics_parser.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,12 @@ def _create_contract(self, player):
104104
)
105105
return contract
106106

107-
def _get_value_from_multivalue_table_cell(self, field, index):
107+
@staticmethod
108+
def _get_value_from_multivalue_table_cell(field, index):
108109
return field.get_text().split(MULTIVALUE_SEPARATOR)[index].strip()
109110

110-
def _get_ep_tp_value_from_table_cell(self, field):
111+
@staticmethod
112+
def _get_ep_tp_value_from_table_cell(field):
111113
return field.get_text().strip('\n').split('\n')[0].strip('\n').strip('\t').replace('.', '')
112114

113115
def _get_equity_value_from_table_cell(self, field):

core/parsers/stadium_statistics_parser.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,22 @@ def parse_html(self, soup):
4141
security_row = stadium_items[2]
4242
parking_row = stadium_items[3]
4343

44-
if StadiumStatisticsParser._is_under_construction(light_row) and last_stadium_level:
44+
if self._is_under_construction(light_row) and last_stadium_level:
4545
light = last_stadium_level.light
4646
else:
4747
light = self._create_stadium_level_item_from_row(light_row)
4848

49-
if StadiumStatisticsParser._is_under_construction(screen_row) and last_stadium_level:
49+
if self._is_under_construction(screen_row) and last_stadium_level:
5050
screen = last_stadium_level.screen
5151
else:
5252
screen = self._create_stadium_level_item_from_row(screen_row)
5353

54-
if StadiumStatisticsParser._is_under_construction(security_row) and last_stadium_level:
54+
if self._is_under_construction(security_row) and last_stadium_level:
5555
security = last_stadium_level.security
5656
else:
5757
security = self._create_stadium_level_item_from_row(security_row)
5858

59-
if StadiumStatisticsParser._is_under_construction(parking_row) and last_stadium_level:
59+
if self._is_under_construction(parking_row) and last_stadium_level:
6060
parking = last_stadium_level.parking
6161
else:
6262
parking = self._create_stadium_level_item_from_row(parking_row)
@@ -80,11 +80,12 @@ def _is_under_construction(stadium_attribute):
8080
return stadium_attribute.find_all('td')[1].img is not None and \
8181
'underconst' in stadium_attribute.find_all('td')[1].img['src']
8282

83-
def _create_stadium_level_item_from_row(self, row):
83+
@staticmethod
84+
def _create_stadium_level_item_from_row(row):
8485
stadium_level_item, _ = StadiumLevelItem.objects.get_or_create(
8586
current_level=row.find_all('td')[2].span.get_text(),
86-
value=self.strip_euro_sign(row.find_all('td')[4].span.get_text().replace('.', '').strip()),
87-
daily_costs=self.strip_euro_sign(row.find_all('td')[5].span.get_text().replace('.', '').strip())
87+
value=BaseParser.strip_euro_sign(row.find_all('td')[4].span.get_text().replace('.', '').strip()),
88+
daily_costs=BaseParser.strip_euro_sign(row.find_all('td')[5].span.get_text().replace('.', '').strip())
8889
)
8990

9091
return stadium_level_item

core/views.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,10 @@ def get(self, request, *args, **kwargs):
160160
class GetChecklistItemsForTodayView(CsrfExemptMixin, JsonRequestResponseMixin, View):
161161
def get(self, request, *args, **kwargs):
162162
current_matchday = Matchday.get_current()
163-
next_matchday_number = current_matchday.number + 1
164163
home_match_tomorrow = Match.objects.filter(
165164
user=request.user,
166165
matchday__season__number=current_matchday.season.number,
167-
matchday__number=next_matchday_number,
166+
matchday__number=current_matchday.number + 1,
168167
is_home_match=True
169168
)
170169
checklist_items = ChecklistItem.objects.filter(checklist__user=request.user)

0 commit comments

Comments
 (0)