-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlvbet.py
185 lines (167 loc) · 7.31 KB
/
lvbet.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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
from selenium import webdriver
from bs4 import BeautifulSoup
import Fortuna
import time
import unidecode
import database
bookie = "Lvbet"
database.delete_all_lvbet_tables()
database.create_all_lvbet_tables()
def load_countries(sports_container):
countries = []
for a in sports_container:
link_text = a.attrs['href']
if link_text != "/pl/zaklady-bukmacherskie" and link_text != "/pl/zaklady-bukmacherskie/--":
print("Link: https://lvbet.pl" + link_text)
country_site = "https://lvbet.pl" + link_text
countries.append(country_site)
return countries
def load_leagues(countries, driver):
counter = 0
for x in countries:
print(x)
driver.get(x)
page_content = BeautifulSoup(driver.page_source, "html.parser")
leagues_container = page_content('a', class_='col-d-3 col-mt-4 col-st-6 col-sm-12')
for y in leagues_container:
link_text = y.attrs['href']
if link_text != '/pl/zaklady-bukmacherskie' and link_text != '/pl/zaklady-bukmacherskie/--':
print('https://lvbet.pl' + link_text)
league_site = 'https://lvbet.pl' + link_text
league_id = counter
league_name = "league " + str(counter)
database.insert_league(bookie, league_id, league_name, league_site)
counter = counter + 1
def load_matches(driver):
football_leagues = database.get_leagues(bookie)
counter = 0
for x in football_leagues:
link = x[1]
print(link)
driver.get(str(link))
time.sleep(3)
text = link[:link.rfind('--')-1]
slash = text.rfind('/')
text = text[slash + 1:]
p = text.rfind('%')
dash = text.rfind('-')
if (p > 0):
text2 = text[:p]
else:
text2 = text
if text2.endswith('-'):
text2 = text2[:-1]
dash = text2.rfind('-')
dashtext = text2[dash + 1:]
newdashtext = ' ' + dashtext + ' '
text_array = list(text2)
if '-' in text_array:
isdash = 1
else:
isdash = 0
while isdash == 1:
index = text_array.index('-')
text_array[index] = ' '
if '-' in text_array:
isdash = 1
else:
isdash = 0
newtext = "".join(text_array)
page_content = BeautifulSoup(driver.page_source, "html.parser")
matches_container = page_content('div', class_='row lv-table-entry')
for y in matches_container:
oddsarray = []
oddsarray2 = []
teams = y('div', class_='col-d-5 col-t-12 teams')
odds = y('div', class_="col-d-2 col-md-3 col-sd-2 col-t-3 col-st-6 col-sm-12")
odds2 = y('div', class_="col-d-2 col-md-3 col-sd-2 col-t-3 col-st-6 col-sm-hidden")
date = y('div', class_='date')
hour = date[0].text[:5]
day = date[0].text[5:7]
month = date[0].text[-2:-1]
date = "2019-" + month + "-" + day + " " + hour
print(date)
foramoment = unidecode.unidecode(teams[0].text.lower())
if foramoment.find(newdashtext) > 0:
slice = foramoment.find(newdashtext)
slice = slice + len(dashtext)
else:
slice = foramoment.find(dashtext)
slice = slice + len(dashtext)
# wyłuskanie zespołów
if teams[0].text[slice + 2:].count(' - ') > 1:
index = teams[0].text[slice + 2:].find(' - ')
slice = slice + index + 1
index = teams[0].text[slice:].find(' ')
slice = slice + index
teams = teams[0].text[slice + 2:]
dash = teams.find('-')
if (teams[:dash].lstrip() != teams[dash + 2:].rstrip()): # wykluczenie nazw zakladow na zwyciezcow
team1 = teams[:dash - 2].lstrip()
team2 = teams[dash + 2:].rstrip()
if team1 != '':
database.insert_match(bookie, counter, team1, team2, date, x[0])
print(team1 + ' - ' + team2)
try:
oddsarray = odds[0].text.split(' ')
except:
try:
oddsarray = y('div', class_='col-d-6 col-t-9 col-st-12')[0].text.split(' ')
except:
try:
oddsarray = y('div', class_='col-d-3 col-md-3 col-t-5 col-st-6')[
0].text.split(' ')
except:
print('brak array')
try:
oddsarray2 = odds2[0].text.split(' ')
except:
print('brak array2')
if oddsarray2 and oddsarray2 != ['']:
try:
home = oddsarray[1]
draw = oddsarray[3]
away = oddsarray[5]
hd = oddsarray2[1]
da = oddsarray2[3]
ha = oddsarray2[5]
print(home + ' ' + draw + ' ' + away + ' ' + hd + ' ' + da + ' ' + ha)
if database.is_match_in_db(bookie, counter):
if not database.compare_odds(bookie, counter, (float(home), float(draw), float(away), float(hd), float(da), float(ha))):
database.update_odds(bookie, counter, home, draw, away, hd, da, ha)
else:
database.insert_odds(bookie, counter, home, draw, away, hd, da, ha)
# zapis do bazy danych meczu (powiązanie z kursami po id)
#database.insert_match(bookie, counter, team1, team2, date, x[0])
except:
print("Problem z listami odds")
else:
try:
home = oddsarray[1]
draw = oddsarray[3]
away = oddsarray[5]
print(home + ' ' + draw + ' ' + away)
if database.is_match_in_db(bookie, counter):
if not database.compare_odds(bookie, counter, (float(home), float(draw), float(away))):
database.update_odds(bookie, counter, home, draw, away)
else:
database.insert_odds(bookie, counter, home, draw, away)
# zapis do bazy danych meczu (powiązanie z kursami po id)
#database.insert_match(bookie, counter, team1, team2, date, x[0])
except:
print("Problem z listami odds bez odds2")
counter = counter + 1
def get_driver():
driver = webdriver.Firefox()
return driver
def scrap():
driver = get_driver()
driver.get('https://lvbet.pl/pl/zaklady-bukmacherskie/5/pilka-nozna')
page_content = BeautifulSoup(driver.page_source, "html.parser")
sports_container = page_content('a', class_='col-d-3 col-mt-4 col-st-6 col-sm-12')
countries = load_countries(sports_container)
load_leagues(countries, driver)
load_matches(driver)
driver.close()
if __name__ == '__main__':
scrap()