-
Notifications
You must be signed in to change notification settings - Fork 2
/
betscrape.py
141 lines (125 loc) · 4.1 KB
/
betscrape.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
import time
from LatinFixer import LatinFix
from pandasmemuc import MeMuc
from PrettyColorPrinter import add_printer # optional
from a_pandas_ex_bs4df_lite import pd_add_bs4_to_df_lite
import pandas as pd
from a_pandas_ex_apply_ignore_exceptions import pd_add_apply_ignore_exceptions
pd_add_apply_ignore_exceptions()
add_printer(1)
pd_add_bs4_to_df_lite()
devices = MeMuc()
def wait_for_element_and_click(fu, deviceindex, timeout=60, click=True):
df2 = pd.DataFrame()
timeoutfinal = time.time() + timeout
while df2.empty:
try:
if time.time().__gt__(timeoutfinal):
raise TimeoutError("Timeout!!")
uia = devices.get_ui_automator_df(deviceindex)
df2 = uia.loc[fu(uia)]
except AttributeError:
continue
if click:
df2.iloc[0].ff_bb_tap_exact_center()
def get_mhtml_file(deviceindex):
newest_archive = (
[
x
for x in devices.iloc[
deviceindex
].bb_adbtools.aa_execute_multiple_adb_shell_commands(
"ls -t /sdcard/Download/"
)
if b"bet365" in x and b"mhtml" in x
][0]
.decode("utf-8")
.strip()
)
htmlcode = b"".join(
devices.iloc[deviceindex].bb_adbtools.aa_execute_multiple_adb_shell_commands(
[f'cat "/sdcard/Download/{newest_archive}"']
)
).replace(b"\r\n", b"\n")
return htmlcode
def download_data(
link="https://www.bet365.com/#/AC/B1/C1/D1002/E88369731/G40/",
deviceindex=5,
timeout=60,
):
devices.iloc[deviceindex].bb_adbtools.aa_open_website(link)
wait_for_element_and_click(
fu=lambda uia: uia.bb_content_desc == "More options",
deviceindex=deviceindex,
timeout=timeout,
)
wait_for_element_and_click(
fu=lambda uia: uia.bb_content_desc == "Download",
deviceindex=deviceindex,
timeout=timeout,
)
wait_for_element_and_click(
fu=lambda uia: uia.bb_resource_id == "com.android.chrome:id/positive_button",
deviceindex=deviceindex,
timeout=timeout,
)
wait_for_element_and_click(
fu=lambda uia: (uia.bb_class == "android.widget.Button") & (uia.bb_text == "Open"),
deviceindex=deviceindex,
timeout=timeout,
click=False,
)
htmlcode = get_mhtml_file(deviceindex)
df = pd.Q_bs4_to_df_lite(htmlcode, parser="lxml")
teams = (
df.loc[df.aa_value == "rcl-ParticipantFixtureDetails_TeamNames"]
.ds_apply_ignore(
[pd.NA, pd.NA],
lambda x: [
LatinFix(x.aa_contents[0].text).apply_wrong_chars(),
LatinFix(x.aa_contents[1].text).apply_wrong_chars(),
],
axis=1,
result_type="expand",
)
.rename(columns={0: "team1", 1: "team2"})
.reset_index(drop=True)
)
bookcloses_cat = (
df.loc[df.aa_value == "rcl-ParticipantFixtureDetails_Details"]
.ds_apply_ignore(
[
pd.NA,
pd.NA,
],
lambda x: [y.text for y in x.aa_contents][:2],
axis=1,
result_type="expand",
)
.rename(columns={0: "book_closes", 1: "category_type"})
.reset_index(drop=True)
)
betdata = pd.DataFrame(
(
df.loc[
(df.aa_name == "span") & (df.aa_value == "sgl-ParticipantOddsOnly80_Odds")
].ds_apply_ignore(pd.NA, lambda x: float(x.aa_contents[0].text), axis=1)
)
.__array__()
.reshape((3, len(teams)))
.T,
columns=["bet_1", "bet_x", "bet_2"],
)
return pd.concat([teams, bookcloses_cat, betdata], axis=1)
serie_a = download_data(
link="https://www.bet365.com/#/AC/B1/C1/D1002/E88369731/G40/",
deviceindex=5,
timeout=60,
)
print(serie_a)
serie_b = download_data(
link="https://www.bet365.com/#/AC/B1/C1/D1002/E88638566/G40/",
deviceindex=5,
timeout=60,
)
print(serie_b)