-
Notifications
You must be signed in to change notification settings - Fork 0
/
mines.py
300 lines (246 loc) · 8.7 KB
/
mines.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
from datetime import datetime
from time import sleep
from threading import Thread
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import Select
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service as ChromeService
import keyboard
import random
import requests
import json
RESULT_WINN = "Win"
RESULT_LOSS = "Loss"
RESULT_LOSS_1 = "Loss"
RESULT_LOSS_2 = "Loss"
RESULT_WinLoss_0 = "Win" # This is not used.
RESULT_WinLoss_1 = "Loss" # This is not used.
RESULT_WinLoss_2 = "Win" # This is not used.
initChipValue = 0.0001
betOption = {}
with open("strategy.json", "r") as file:
betOption = json.load(file)
BUTTON_BET = 'Bet'
BUTTON_HALF = '1/2'
BUTTON_DOUBLE = '2x'
ID = {
BUTTON_BET: "bet-button",
BUTTON_HALF: "input-button-wrap@0",
BUTTON_DOUBLE: "input-button-wrap@1",
}
pressedKey = False
Is_End = False
url = "https://stake.com/casino/games/mines"
options = Options()
options.add_experimental_option("debuggerAddress", "127.0.0.1:9030") #9030
options.add_argument("user-agent=Chrome/121.0.6167.185")
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options)
def clickButton(buttonName):
if not pressedKey:
button = None
buttonId = ID[buttonName]
if "input-button-wrap" in buttonId:
button = findElement(driver, By.CLASS_NAME, "input-button-wrap").find_elements(
By.TAG_NAME, 'button')[int(buttonId.split("@")[1])]
else:
button = findElement(driver, By.CSS_SELECTOR,
f'button[data-testid="{ID[buttonName]}"]')
if button != None:
try:
button.click()
except:
driver.execute_script("arguments[0].click();", button)
print(
f'{datetime.now().strftime("%H:%M:%S")}, button clicked <{buttonName}>')
sleep(0.5)
def clickSquares(numbers):
findElement(driver, By.CSS_SELECTOR, 'button[data-testid="cashout-button"]')
while not pressedKey:
try:
squareButtons = findElement(driver, By.CLASS_NAME, 'game-content').find_elements(By.TAG_NAME, 'button')
for number in numbers:
sleep(0.1)
try:
driver.find_element(By.CSS_SELECTOR, f'button[data-testid="{ID[BUTTON_BET]}"]')
return RESULT_LOSS
except:
pass
try:
if squareButtons[number - 1].get_attribute("data-revealed") == "false":
squareButtons[number - 1].click()
except:
pass
if squareButtons[numbers[-1] - 1].get_attribute("data-revealed") == "true":
break
sleep(0.2)
except:
pass
sleep(0.1)
def check_if_win_or_not():
result = RESULT_LOSS
while True:
try:
cashoutButton = driver.find_element(By.CSS_SELECTOR, 'button[data-testid="cashout-button"]')
if cashoutButton.text == "Cashout":
result = RESULT_WINN
while True:
cashoutButton.click()
try:
driver.find_element(By.CSS_SELECTOR, f'button[data-testid="bet-button"]')
break
except:
pass
sleep(0.1)
break
except:
pass
try:
driver.find_element(By.CSS_SELECTOR, f'button[data-testid="bet-button"]')
break
except:
pass
sleep(0.1)
return result
def setMines(minesCount):
if minesCount > 0 and minesCount < 25:
selectElement = findElement(driver, By.NAME, 'mines-count')
if selectElement != None:
select = Select(selectElement)
select.select_by_value(str(minesCount))
print(f'{datetime.now().strftime("%H:%M:%S")}, Mines: {minesCount}')
sleep(0.5)
else:
print(
f'{datetime.now().strftime("%H:%M:%S")}, Mines should be in [1, 24]')
def findElement(driver, by, value):
element = None
timeout = 0
refreshed = False
while not pressedKey:
try:
element = driver.find_element(by, value)
break
except:
if value == 'button[data-testid="cashout-button"]':
timeout += 0.1
if not refreshed and timeout >= 5.0:
driver.refresh()
refreshed = True
sleep(0.1)
return element
def getTotalAmount():
totalAmountElement = findElement(driver, By.CLASS_NAME, 'coin-toggle')
totalAmount = -1
if totalAmountElement != None:
totalAmount = float(totalAmountElement.text)
return totalAmount
def setChipValue(chipValue):
chipValueInput = findElement(driver, By.CLASS_NAME, 'input-content').find_element(By.TAG_NAME, 'input')
if chipValueInput != None:
chipValueInput.send_keys(str(chipValue))
print(f'{datetime.now().strftime("%H:%M:%S")}, Bet Amount: {chipValue}')
sleep(0.5)
def rearrangeSquares():
unique_numbers = set()
while len(unique_numbers) < betOption["Selected Mines"]:
unique_numbers.add(random.randint(1, 25))
squares = list(unique_numbers)
print(f'{datetime.now().strftime("%H:%M:%S")}, Rearranged Squares: {squares}')
return squares
def pressKey():
global pressedKey
while not Is_End:
if keyboard.is_pressed('esc'):
pressedKey = True
print(f'{datetime.now().strftime("%H:%M:%S")} Pressed the [ESC] key\n')
sleep(0.1)
def Martingale():
global Is_End
global pressedKey
chipValue = initChipValue
countWinn = 0
countLoss = 0
squares = rearrangeSquares()
while not Is_End:
setMines(betOption["Total Mines"])
setChipValue(chipValue)
clickButton(BUTTON_BET)
clickSquares(squares)
result = check_if_win_or_not()
if result == RESULT_WINN:
countWinn += 1
else:
countLoss += 1
countWinn = 0
output = f'{datetime.now().strftime("%H:%M:%S")}, {result} ({countWinn} : {countLoss})'
print(output)
# with open('statistics.txt', '+a') as file:
# file.write(output + "\n")
if countWinn == betOption["Win"]["Count"]:
chipValue = initChipValue
countWinn = 0
# countLoss = 0
if countLoss == betOption["Loss"]["Count"]:
chipValue *= betOption[result]["Multiplier"]
countLoss = 0
totalAmount = getTotalAmount()
if chipValue > totalAmount and totalAmount != -1:
print("There is not enough money to bet.")
break
else:
if betOption[result]["Rearrange"]:
squares = rearrangeSquares()
print("\n")
if pressedKey:
print("\n")
response = input(
"It has now stopped running. Press the [y] key to run again, the [n] key to exit.")
if response == "y":
print("\n")
input(
"To run it again, you need to reset all states. Press the [Enter] key after initializing.")
print("\n")
pressedKey = False
else:
break
print(f'{datetime.now().strftime("%H:%M:%S")}, Ended')
Is_End = True
def userVerify(url, payload):
global pressedKey
global Is_End
while True:
sleep(3600)
response = requests.request("POST", url, data=payload)
data = response.json()["data"]
print("")
print(data + "\n")
if data != "Successfully verified":
pressedKey = True
Is_End = True
break
if __name__ == "__main__":
while True:
username = input("username: ")
print("")
password = input("password: ")
print("")
url = "http://87.251.88.14:80/login"
payload = {
'username': username,
'password': password,
'client_id': '123',
'productName' : "mines"
}
response = requests.request("POST", url, data=payload)
data = response.json()["data"]
print(data)
print("")
if data == "Successfully verified":
break
Thread(target=pressKey).start()
Thread(target=userVerify, args=(url, payload, )).start()
Martingale()