66import time
77from datetime import datetime
88
9+ from strats .strats import Strat
10+
911from selenium .webdriver .support import expected_conditions as EC
1012from selenium .webdriver .support .wait import WebDriverWait
1113from 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 ("\n game 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
0 commit comments