Repository navigation
Expand file tree
/
Copy pathprecomputewd.py
More file actions
154 lines (140 loc) · 4.5 KB
/
Copy pathprecomputewd.py
File metadata and controls
154 lines (140 loc) · 4.5 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
"""import packages"""
import urllib.request
# import datetime
lstdates = []
clubes = []
locations = []
homes = []
aways = []
played = []
lsthome = []
lstaway = []
lstgoalshome = []
lstgoalsaway = []
matches = []
lstindexes = []
lstrepeats = []
doc = []
dates_structured = []
def build_match(club, pj):
"""create match structure"""
match = {"club": club,
"pj": pj}
return match
def get_puntos(goalshome, goalsaway):
"""compute points"""
if goalshome > goalsaway:
pointslocal = 3
pointsvisitor = 0
elif goalshome == goalsaway:
pointslocal = 1
pointsvisitor = 1
else:
pointslocal = 0
pointsvisitor = 3
return ([pointslocal, pointsvisitor])
def get_repeats():
"""locate and call data"""
# lstindexes=[]
for line in lines:
if line: # Check if line is not empty
if not line.startswith('Spieltag') and not line.startswith('='):
doc.append(line)
if line.startswith('[') and not line.startswith('Spieltag'):
lstindexes.append(len(doc) - 1) # Use len(doc) - 1 instead of doc.index(line)
for repeat in lstindexes:
i = lstindexes.index(repeat)
if i == 0:
newrepeat = 0
# lstrepeats.append(newrepeat)
else:
newrepeat = 9
lstrepeats.append(newrepeat)
# print(lstindexes)
lstrepeats.append(9)
# print(lstrepeats)
def structure_dates():
"""format and structure dates"""
for fecha in lstdates:
i = lstdates.index(fecha)
for e in range(0, lstrepeats[i]):
fechaformat = fecha.split(' ')
fechaformat = fechaformat[1].split(']')
fechaformat = fechaformat[0].split('.')
if int(fechaformat[1]) >= 8:
# change
year = '2025'
else:
# change
year = '2026'
fechaformat = year+'-'+fechaformat[1].zfill(2)+'-'+fechaformat[0].zfill(2)
dates_structured.append(fechaformat)
URL='https://raw.githubusercontent.com/enadol/merobot/master/bundesliga-2026.txt'
with urllib.request.urlopen(URL) as response:
data = response.read()
data2 = data.decode('utf-8')
file_name = "core.txt"
archivo = open(file_name, "w", newline='\n', encoding='utf-8')
data2 = data2.replace("ö", "oe")
data2 = data2.replace("ü", "ue")
lines = data2.splitlines()
get_repeats()
archivo.close()
for line in lines:
if line.startswith('['):
date = line
lstdates.append(date)
elif line == ' ':
vacia = line
elif line.startswith('Spieltag'):
mday = line
elif "Bundesliga" in line:
titulo = line
else:
if line.startswith(' 20.30'):
line = line.split('20.30')[1]
elif line.startswith(' 18.30'):
line = line.split('18.30')[1]
elif line.startswith(' 15.30'):
line = line.split('15.30')[1]
elif line.startswith(' 18.00'):
line = line.split('18.00')[1]
else:
line = line
location = line.split('-', 1) # puede ser :
locations.append(location) # se puede borrar luego
if len(location) > 1:
home = location[0]
homes.append(home.lstrip())
away = location[1]
aways.append(away)
for index, value in enumerate(homes):
local = value.split(' ')
if local and local[-1].strip():
goalshome = local[-1].strip()
lstgoalshome.append(goalshome)
lsthome.append(local[0].strip())
visitante = aways[index].split(' ')
if visitante and visitante[0].strip():
goalsaway = visitante[0][0]
lstgoalsaway.append(goalsaway)
lstaway.append(visitante[1].strip() if len(visitante) > 1 else '')
structure_dates()
for index, value in enumerate(lsthome):
element = {
"teamhome": lsthome[index],
"teamaway": lstaway[index],
"goalshome": int(lstgoalshome[index]),
"goalsaway": int(lstgoalsaway[index]),
"pointslocal": get_puntos(int(lstgoalshome[index]), int(lstgoalsaway[index]))[0],
"pointsvisitor": get_puntos(int(lstgoalshome[index]), int(lstgoalsaway[index]))[1],
"date": dates_structured[index]
}
matches.append(element)
clubes=list(set(lsthome))
#for club in clubes:
# count = 0
# for index, value in enumerate(lsthome):
# # for y in range(0, len(lsthome)):
# if lsthome[index] == club or lstaway[index] == club:
# count = count+1