Skip to content

Commit fa61e4e

Browse files
authored
Merge pull request #4 from luisrx7/dev
Add tests and autobet script
2 parents 700556c + ef5931b commit fa61e4e

File tree

12 files changed

+1150
-14
lines changed

12 files changed

+1150
-14
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ results1.txt
1010
results2.txt
1111
.txt
1212
creds.py
13+
slices.pickle
14+
autobet.log

autobet.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import logging
2+
import time
3+
4+
import rich
5+
import rich.console
6+
import rich.traceback
7+
import sys
8+
9+
from aviator import Aviator
10+
from strats.custom_strats import DAlembertStrat
11+
12+
rich.traceback.install()
13+
console = rich.console.Console()
14+
15+
16+
logging.basicConfig(format='%(asctime)s %(levelname)s:%(message)s', level=logging.INFO, datefmt='%m/%d/%Y %I:%M:%S', filename="autobet.log")
17+
18+
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
19+
20+
21+
def signal_handler(sig, frame):
22+
global stop
23+
print('You pressed Ctrl+C!')
24+
stop = True
25+
# sys.exit(0)
26+
27+
28+
stop = False
29+
30+
31+
32+
33+
34+
def main():
35+
strat = DAlembertStrat(
36+
description="DAlembertStrat",
37+
start_balance=3000,
38+
base_bet=0.1,
39+
max_bet=1,
40+
multiplier=2,
41+
max_bets=10000,
42+
)
43+
44+
while stop is False:
45+
try:
46+
aviator = Aviator(debug=True, strat=strat)
47+
aviator.login()
48+
aviator.go_to_game()
49+
time.sleep(3)
50+
aviator.setup_auto_bet()
51+
52+
53+
while aviator.in_game() and stop is False:
54+
aviator.wait_for_game_to_finish()
55+
last_result = aviator.get_last_game_result()
56+
aviator.process_bet(float(last_result))
57+
aviator.add_to_log(last_result)
58+
print(f"balance: {aviator.get_balance()}")
59+
except Exception as e:
60+
console.print_exception(show_locals=True)
61+
logging.error(e)
62+
finally:
63+
aviator.close()
64+
65+
if __name__ == "__main__":
66+
main()

aviator/aviator.py

Lines changed: 88 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import time
77
from datetime import datetime
88

9+
from strats.strats import Strat
10+
911
from selenium.webdriver.support import expected_conditions as EC
1012
from selenium.webdriver.support.wait import WebDriverWait
1113
from selenium.common.exceptions import StaleElementReferenceException, NoSuchElementException
@@ -18,12 +20,16 @@ class Aviator(Browser):
1820

1921
def __init__(self, headless=False, test=False, remote_driver=True,
2022
remote_address="127.0.0.1",remote_port=4446, use_cookies=False,
21-
debug=False):
23+
debug=False,strat: Strat = None):
2224
super().__init__(headless= headless, test=test, remote_driver=remote_driver,
2325
remote_address=remote_address,remote_port=remote_port,
2426
use_cookies=use_cookies, profile_path=vars.profile_path)
2527

2628
self.debug = debug
29+
self.strat = strat
30+
31+
if self.strat is not None:
32+
self.strat.reset()
2733

2834
helium.set_driver(self.driver)
2935

@@ -78,11 +84,46 @@ def get_last_game_result(self):
7884
'''
7985
# if self.debug:
8086
# print("getting last game result")
87+
88+
element = self.find_elements(By.XPATH, vars.last_game_result, timeout=0.5)
8189

90+
if element is not None:
91+
return element.text.strip().replace("x", "")
92+
93+
8294
results = self.get_game_results()
8395
if len(results) > 0:
8496
return results[0]
8597

98+
def process_bet(self, result):
99+
'''
100+
check if a strat is defined
101+
if it is, use it to calculate the next bet
102+
if not warn the user that a strat is not defined
103+
'''
104+
if self.debug:
105+
print(f"processing bet for result {result}")
106+
if self.strat is None:
107+
print("WARNING: no strat defined")
108+
return False
109+
110+
self.strat.calculate_bet(result)
111+
if self.debug:
112+
print(f"bet: {self.strat.bet}, multiplier: {self.strat.multiplier}")
113+
114+
if self.strat.bet == 0 or self.strat.multiplier == 0:
115+
if self.debug:
116+
print("bet or multiplier is 0, not placing bet")
117+
return False
118+
119+
if self.place_bet(self.strat.bet, self.strat.multiplier) is False:
120+
if self.debug:
121+
print("could not place bet")
122+
return False
123+
124+
self.strat.gamble()
125+
126+
86127
def get_game_results(self):
87128
'''
88129
get game result
@@ -150,15 +191,13 @@ def wait_for_game_to_finish(self):
150191
print("waiting for game to finish")
151192
last_result = self.get_last_game_result()
152193
while True:
153-
154194
if self.get_last_game_result() != last_result:
155195
break
156196
if self.debug:
157197
print(".", end="")
158-
time.sleep(0.5)
198+
time.sleep(0.1)
159199
if self.debug:
160-
print("")
161-
print("game finished")
200+
print("\ngame finished")
162201

163202
def add_to_log(self, result):
164203
'''
@@ -170,6 +209,50 @@ def add_to_log(self, result):
170209
with open("results.txt", "a") as f:
171210
f.write(f"{datetime.now().strftime('%d-%m-%Y %H:%M:%S')},{result}\n")
172211

212+
213+
def setup_auto_bet(self):
214+
'''
215+
click the buttons to setup auto cashout
216+
'''
217+
if self.debug:
218+
print("setting up auto bet")
219+
220+
if self.click_button(vars.bet_type_button) is False:
221+
if self.debug:
222+
print("could not click bet type button")
223+
return False
224+
if self.click_button(vars.auto_cashout_button) is False:
225+
if self.debug:
226+
print("could not click auto cashout button")
227+
return False
228+
229+
230+
def place_bet(self,amount, multiplier):
231+
'''
232+
place bet with amount and multiplier
233+
'''
234+
if self.debug:
235+
print(f"setting bet amount to {amount} at multiplier {multiplier}")
236+
237+
238+
if self.send_keys(vars.bet_amount_input_box, str(amount)) is False:
239+
if self.debug:
240+
print("could not set bet amount")
241+
return False
242+
243+
if self.send_keys(vars.multiplier_input_box, str(multiplier)) is False:
244+
if self.debug:
245+
print("could not set multiplier")
246+
return False
247+
248+
if self.click_button(vars.place_bet_button) is False:
249+
if self.debug:
250+
print("could not click place bet button")
251+
return False
252+
253+
return True
254+
255+
173256
def go_to_game(self):
174257
wait = WebDriverWait(self.driver, 10)
175258

aviator/vars.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,20 @@
88

99
game_name = '//*[@id="slots"]/div[2]/div[1]/div[1]'
1010

11-
last_game_result = 'body > app-root > app-game > div > div.main-container > div.w-100.h-100 > div > div.game-play > div.result-history.disabled-on-game-focused.my-2 > app-stats-widget > div > div.payouts-wrapper > div > app-bubble-multiplier:nth-child($ROUND$)'
12-
11+
last_game_results = 'body > app-root > app-game > div > div.main-container > div.w-100.h-100 > div > div.game-play > div.result-history.disabled-on-game-focused.my-2 > app-stats-widget > div > div.payouts-wrapper > div > app-bubble-multiplier:nth-child($ROUND$)'
12+
last_game_result = "/html/body/app-root/app-game/div/div[1]/div[2]/div/div[2]/div[1]/app-stats-widget/div/div[1]/div/app-bubble-multiplier[1]/div"
1313

1414
open_new_window_button = '//*[@id="wrapper_game_area"]/div/ul/li[3]/a'
1515

16-
balance = '/html/body/app-root/app-game/div/div[1]/div[1]/app-header/div/div[2]/div[1]/div[1]/div/span[1]'
16+
balance = '/html/body/app-root/app-game/div/div[1]/div[1]/app-header/div/div[2]/div[1]/div[1]/div/span[1]'
17+
18+
19+
#bets
20+
21+
22+
bet_type_button = '/html/body/app-root/app-game/div/div[1]/div[2]/div/div[2]/div[3]/app-bet-controls/div/app-bet-control[1]/div/app-navigation-switcher/div/button[2]'
23+
auto_cashout_button = '/html/body/app-root/app-game/div/div[1]/div[2]/div/div[2]/div[3]/app-bet-controls/div/app-bet-control[1]/div/div[3]/div[2]/div[1]/app-ui-switcher'
24+
place_bet_button = '/html/body/app-root/app-game/div/div[1]/div[2]/div/div[2]/div[3]/app-bet-controls/div/app-bet-control[1]/div/div[1]/div[2]/button'
25+
26+
bet_amount_input_box = '/html/body/app-root/app-game/div/div[1]/div[2]/div/div[2]/div[3]/app-bet-controls/div/app-bet-control[1]/div/div[1]/div[1]/app-spinner/div/div[2]/input'
27+
multiplier_input_box = '/html/body/app-root/app-game/div/div[1]/div[2]/div/div[2]/div[3]/app-bet-controls/div/app-bet-control[1]/div/div[3]/div[2]/div[2]/div/app-spinner/div/div[2]/input'

browser/browser.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from selenium.webdriver.common.by import By
77
from selenium.webdriver.support import expected_conditions as EC
88
from selenium.webdriver.support.wait import WebDriverWait
9+
from selenium.webdriver.common.keys import Keys
910

1011
import os
1112

@@ -40,6 +41,18 @@ def __init__(self,headless = True,test = False,remote_driver = True,
4041
self.chrome_options.add_experimental_option('excludeSwitches',
4142
['enable-logging'])
4243

44+
# Adding argument to disable the AutomationControlled flag
45+
self.chrome_options.add_argument("--disable-blink-features=AutomationControlled")
46+
47+
# Exclude the collection of enable-automation switches
48+
self.chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
49+
50+
# Turn-off userAutomationExtension
51+
self.chrome_options.add_experimental_option("useAutomationExtension", False)
52+
53+
# Setting the driver path and requesting a page
54+
55+
4356
if self.profile_path != "":
4457
print("profile path",self.profile_path)
4558
os.makedirs(self.profile_path, exist_ok=True)
@@ -51,6 +64,9 @@ def __init__(self,headless = True,test = False,remote_driver = True,
5164
self.driver = webdriver.Chrome(service=ChromeDriverManager().install(), # type: ignore # noqa: E501
5265
options=self.chrome_options)
5366

67+
# Changing the property of the navigator value for webdriver to undefined
68+
self.driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
69+
5470
self.driver.implicitly_wait(5)
5571

5672
def find_elements(self,by, value, timeout=5):
@@ -116,4 +132,16 @@ def click_button(self, button_id):
116132
buttons[0].click()
117133
return True
118134
return False
135+
136+
def send_keys(self,element_id,keys,clear_first = True):
137+
element = self.find_elements(By.XPATH, element_id,timeout=1)
138+
if element is None:
139+
return False
140+
141+
if clear_first:
142+
element.send_keys(Keys.CONTROL + "a")
143+
144+
element.send_keys(keys)
145+
146+
return True
119147

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ services:
55
- "4446:4444"
66
# env_file:
77
# - ./.env
8+
9+
environment:
10+
- VNC_NO_PASSWORD=1

0 commit comments

Comments
 (0)