-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (51 loc) · 1.68 KB
/
main.py
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
import pandas as pd
DataType = {
'scores_and_fixtures' : 'schedule',
'shooting' : 'shooting',
'goalkeeping': 'keeper',
'passing' : 'passing',
'pass_types' : 'passing_types',
'goal_and_shot_creation': 'gca',
'defensive_actions': 'defense',
'possession': 'possession',
'miscellaneous_stats': 'misc'
}
Teams = {
# Laliga Top 5
'206d90db': 'Barcelona',
'53a2f082': 'Real-Madrid',
'db3b9613': 'Atletico-Madrid',
'e31d1cd9': 'Real-Sociedad',
'2a8183b3': 'Villarreal',
}
Comps = {
'all_comps': 'All-Competitions',
# Laliga Competitions
'c8': 'Champions-League',
'c12': 'La-Liga',
'c19': 'Europa-League',
'c122': 'UEFA-Super-Cup',
'c569': 'Copa-del-Rey',
'c646': 'Supercopa-de-Espana',
'c882': 'Europa-Conference-League',
}
class MatchLogsLink:
def __init__(self,team_id,year,comp_id, log_type):
self.team_id = team_id
self.year = year
self.comp_id = comp_id
self.log_type = log_type
self.link = f'https://fbref.com/en/squads/{self.team_id}/{self.year}/matchlogs/{self.comp_id}/{DataType[self.log_type]}/{Teams[self.team_id]}-Match-Logs-{Comps[self.comp_id]}'
def __repr__(self):
return self.link
class Data:
def __init__(self, link: MatchLogsLink):
self.link = str(link)
def fbref2pandas(self):
try:
data_list = pd.read_html(self.link)
except Exception as e:
print(f'The link {repr(self.link)} is not able to scrape the table from the FBRef website. Try checking for some typos.')
for table in data_list:
df = pd.DataFrame(table)
return df