-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_processor.py
More file actions
executable file
·73 lines (44 loc) · 1.59 KB
/
data_processor.py
File metadata and controls
executable file
·73 lines (44 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from bs4 import BeautifulSoup
from Stat import Stat
def _get_team_stat(row, index=0, cast=int, sep=':', sep_pos=0):
return int(row.find_all('td')[index].text.split(sep)[sep_pos])
def _get_team_played(row):
return _get_team_stat(row, index=3)
def _get_team_won(row):
return _get_team_stat(row, index=4)
def _get_team_draw(row):
return _get_team_stat(row, index=5)
def _get_team_lost(row):
return _get_team_stat(row, index=6)
def _get_team_goals_for(row):
return _get_team_stat(row, index=7, sep_pos=0)
def _get_team_goals_against(row):
return _get_team_stat(row, index=7, sep_pos=1)
def _get_team_goals_diff(row):
return _get_team_stat(row, index=8)
def _get_team_points(row):
return _get_team_stat(row, index=9, sep_pos=0)
def _get_team_points_adjusted(row):
return (_get_team_won(row) * 3) + _get_team_draw(row)
def get_standings_table(raw_data):
soup_data = BeautifulSoup(raw_data, 'html.parser')
# Get standings table.
raw_table = soup_data.find_all(
'table',
attrs={'class': 'standard_tabelle'}
)[1]
# Extract the data rows from the raw table.
return raw_table.find_all('tr')[1:]
def get_team_name(row):
return row.find('a')['title']
STAT_PROCESSOR_MAP = {
Stat.PLAYED: _get_team_played,
Stat.WON: _get_team_won,
Stat.DRAW: _get_team_draw,
Stat.LOST: _get_team_lost,
Stat.GOALS_FOR: _get_team_goals_for,
Stat.GOALS_AGAINST: _get_team_goals_against,
Stat.GOAL_DIFF: _get_team_goals_diff,
Stat.POINTS: _get_team_points,
Stat.POINTS_ADJUSTED: _get_team_points_adjusted
}