forked from ChrisMusson/FBRef_DB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
71 lines (66 loc) · 1.68 KB
/
utils.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
66
67
68
69
70
71
ignore = {
"bundesliga": {
"5dc40876",
"9c6a24db",
"e262266b",
"f5e7a5c2",
"434865ef",
"2f2a35fa",
"dc47142c",
"948872ab",
"ac3eb7f6",
"d50b48fe",
"2c791569",
"f9a47a86",
},
"ligue_1": {
"f927719d",
"06517ea5",
"bfd434c1",
"ea5db1c4",
"621f8a81",
"28ce9808",
"f1560d55",
"78ed8c0d",
},
"serie_a": {"e0449015"},
"primeira_liga": {
"3f514a62",
"9c028e7e",
"c8cd6748",
"65aab877",
"fb49ed3b",
"b4f01c0d",
},
"other":{
"e0a20cfe", # SerieA_2020-2021 - Verona:Roma - Result Awarded - Registration Error
"c34bbc21", # Bundesliga_2021-2022 - Bochum:Monchengladbach - Abandoned - Fan Trouble}
}
}
def clean_row(row):
for i, d in enumerate(row):
if d == "":
row[i] = None
elif "." in d:
row[i] = float(d)
else:
try:
row[i] = int(d)
except ValueError:
continue
return row
def insert(cursor, table_name, data):
if data == [] or len(data[0]) == 0:
return
q_marks = ",".join(["?"] * len(data[0]))
cursor.executemany(f"INSERT INTO {table_name} VALUES ({q_marks})", data)
def get_matches_in_database(cursor, competition, season):
matches = cursor.execute(
"""SELECT DISTINCT s.match_id
FROM Summary s
LEFT JOIN Match m
ON s.match_id = m.match_id
WHERE m.competition = ? AND m.season = ?""",
(competition, season),
).fetchall()
return set([x[0] for x in matches])