Skip to content

Commit 3db9d9e

Browse files
authored
Merge pull request #5 from luisrx7/dev
add plots to better visualize the results of checker script
2 parents fa61e4e + d291df3 commit 3db9d9e

File tree

11 files changed

+7619
-69
lines changed

11 files changed

+7619
-69
lines changed

README.md

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Welcome to the AviatorStratChecker repository! This project aims to provide a po
1212

1313
- Effortlessly scrape Aviator game data from 22bet.
1414
- Design, simulate, and fine-tune strategies using historical data.
15+
- Automatically bet using your own strategies.
1516
- Collaborate with the community by contributing to the project.
1617

1718
## Getting Started
@@ -46,15 +47,20 @@ To set up and use AviatorStratChecker, follow these simple steps:
4647
password = "your-password"
4748
```
4849

49-
5. **Run Selenium using Docker:**
50+
5. **Install docker and docker-compose:**
51+
- [Docker](https://docs.docker.com/get-docker/)
52+
- [Docker Compose](https://docs.docker.com/compose/install/)
53+
54+
55+
6. **Run Selenium using Docker:**
5056
```bash
5157
docker-compose up
5258
```
5359

5460

55-
5. **Execute the script to start gathering live results:**
61+
7. **Execute the script to start gathering live results:**
5662
```bash
57-
python main.py
63+
python scrape.py
5864
```
5965

6066

@@ -84,6 +90,37 @@ To set up and use AviatorStratChecker, follow these simple steps:
8490
python checker.py
8591
```
8692

93+
94+
## After finding a good strategy
95+
96+
1. **Edit the file autobet.py to add your strategy:**
97+
```python
98+
from strats.custom_strats import BestStrat
99+
100+
def main():
101+
strat = BestStrat(
102+
description="BestStrat - Example",
103+
start_balance=3000,
104+
base_bet=0.1,
105+
max_bet=0.5,
106+
multiplier=1.9,
107+
max_bets=10000,
108+
)
109+
```
110+
2. **Run the autobet.py script to start betting:**
111+
```bash
112+
python autobet.py
113+
```
114+
115+
## TODO
116+
- Add tests to the existing Strats
117+
- Add tests to the code
118+
- Find some way to scrape past data from the game (maybe using requests)
119+
- Add a way to save the data to a database instead of a csv file
120+
- Add a way to compare strategies
121+
- Add better indicators to the strategies to help the user to decide which one to use
122+
123+
87124
## Contributing
88125
We welcome contributions! If you encounter any issues or have suggestions, please open an issue or submit a pull request.
89126

autobet.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ def signal_handler(sig, frame):
3030

3131

3232

33-
3433
def main():
3534
strat = DAlembertStrat(
3635
description="DAlembertStrat",
3736
start_balance=3000,
3837
base_bet=0.1,
39-
max_bet=1,
40-
multiplier=2,
38+
max_bet=0.5,
39+
multiplier=1.9,
4140
max_bets=10000,
4241
)
4342

@@ -55,7 +54,7 @@ def main():
5554
last_result = aviator.get_last_game_result()
5655
aviator.process_bet(float(last_result))
5756
aviator.add_to_log(last_result)
58-
print(f"balance: {aviator.get_balance()}")
57+
logging.info(f"balance: {aviator.get_balance()}")
5958
except Exception as e:
6059
console.print_exception(show_locals=True)
6160
logging.error(e)

aviator/aviator.py

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
from selenium.webdriver.support.wait import WebDriverWait
1313
from selenium.common.exceptions import StaleElementReferenceException, NoSuchElementException
1414

15+
import logging
16+
17+
logger = logging.getLogger(__name__)
18+
1519
class Aviator(Browser):
1620
'''
1721
this class will interact with the browser
@@ -49,15 +53,15 @@ def login(self):
4953

5054
def logged_in(self):
5155
if self.debug:
52-
print("checking if logged in")
56+
logger.debug("checking if logged in")
5357
element = helium.S("#user-money")
5458
if element.exists():
5559
if self.debug:
56-
print("logged in")
60+
logger.debug("logged in")
5761
return True
5862
else:
5963
if self.debug:
60-
print("not logged in")
64+
logger.debug("not logged in")
6165
return False
6266

6367

@@ -66,26 +70,26 @@ def in_game(self):
6670
check if we are in game
6771
'''
6872
if self.debug:
69-
print("checking if in game")
73+
logger.debug("checking if in game")
7074

7175
element = self.find_elements(By.XPATH, vars.game_name, timeout=0.5)
7276
if element or self.driver.title == "Aviator":
7377
if self.debug:
74-
print("in game")
78+
logger.debug("in game")
7579
return True
7680

7781
if self.debug:
78-
print("not in game")
82+
logger.debug("not in game")
7983
return False
8084

8185
def get_last_game_result(self):
8286
'''
8387
get last game result
8488
'''
8589
# if self.debug:
86-
# print("getting last game result")
90+
# logger.debug("getting last game result")
8791

88-
element = self.find_elements(By.XPATH, vars.last_game_result, timeout=0.5)
92+
element = self.find_elements(By.XPATH, vars.last_game_result, timeout=1)
8993

9094
if element is not None:
9195
return element.text.strip().replace("x", "")
@@ -102,23 +106,23 @@ def process_bet(self, result):
102106
if not warn the user that a strat is not defined
103107
'''
104108
if self.debug:
105-
print(f"processing bet for result {result}")
109+
logger.debug(f"processing bet for result {result}")
106110
if self.strat is None:
107-
print("WARNING: no strat defined")
111+
logger.debug("WARNING: no strat defined")
108112
return False
109113

110114
self.strat.calculate_bet(result)
111115
if self.debug:
112-
print(f"bet: {self.strat.bet}, multiplier: {self.strat.multiplier}")
116+
logger.debug(f"bet: {self.strat.bet}, multiplier: {self.strat.multiplier}")
113117

114118
if self.strat.bet == 0 or self.strat.multiplier == 0:
115119
if self.debug:
116-
print("bet or multiplier is 0, not placing bet")
120+
logger.debug("bet or multiplier is 0, not placing bet")
117121
return False
118122

119123
if self.place_bet(self.strat.bet, self.strat.multiplier) is False:
120124
if self.debug:
121-
print("could not place bet")
125+
logger.debug("could not place bet")
122126
return False
123127

124128
self.strat.gamble()
@@ -132,6 +136,10 @@ def get_game_results(self):
132136

133137
# Find the div element with class "payouts-block"
134138
payouts_div = self.find_elements(By.CLASS_NAME, "payouts-block")
139+
if payouts_div is None:
140+
if self.debug:
141+
logger.debug("could not get game results")
142+
return []
135143

136144
# Find all elements with class "bubble-multiplier" within the payouts div
137145
multiplier_elements = payouts_div.find_elements(By.CLASS_NAME, "bubble-multiplier")
@@ -152,11 +160,11 @@ def get_game_results(self):
152160

153161
if len(results) > 0:
154162
# if self.debug:
155-
# print("got game results")
163+
# logger.debug("got game results")
156164
return results
157165
else:
158166
if self.debug:
159-
print("could not get game results")
167+
logger.debug("could not get game results")
160168

161169

162170
return []
@@ -167,18 +175,28 @@ def get_balance(self):
167175
get balance
168176
'''
169177
if self.debug:
170-
print("getting balance")
178+
logger.debug("getting balance")
171179
element = self.find_elements(By.XPATH, vars.balance)
172180
#element is a span with the balance
173181
if element:
174182
if self.debug:
175-
print("got balance")
183+
logger.debug("got balance")
176184
return element.text
177185
else:
178186
if self.debug:
179-
print("could not get balance")
187+
logger.debug("could not get balance")
180188
return None
181189

190+
191+
def disconnected(self):
192+
'''
193+
check if disconnected warning is displayed
194+
'''
195+
disconnected_element = self.find_elements(By.XPATH, vars.disconnected_warning, timeout=0.5)
196+
if disconnected_element is not None:
197+
return True
198+
return False
199+
182200
def wait_for_game_to_finish(self):
183201
'''
184202
wait for game to finish
@@ -188,24 +206,30 @@ def wait_for_game_to_finish(self):
188206
'''
189207

190208
if self.debug:
191-
print("waiting for game to finish")
209+
logger.debug("waiting for game to finish")
192210
last_result = self.get_last_game_result()
193211
while True:
194-
if self.get_last_game_result() != last_result:
212+
if self.disconnected():
213+
if self.debug:
214+
logger.debug("disconnected")
195215
break
216+
result = self.get_last_game_result()
217+
if result is not None:
218+
if result != last_result :
219+
break
196220
if self.debug:
197-
print(".", end="")
221+
logger.debug(".", end="")
198222
time.sleep(0.1)
199223
if self.debug:
200-
print("\ngame finished")
224+
logger.debug("\ngame finished")
201225

202226
def add_to_log(self, result):
203227
'''
204228
add result to results.txt in this
205229
format timestamp (format dd-mm-yyyy hh:mm:ss),result
206230
'''
207231
if self.debug:
208-
print(f"adding result {result} to log")
232+
logger.debug(f"adding result {result} to log")
209233
with open("results.txt", "a") as f:
210234
f.write(f"{datetime.now().strftime('%d-%m-%Y %H:%M:%S')},{result}\n")
211235

@@ -215,15 +239,15 @@ def setup_auto_bet(self):
215239
click the buttons to setup auto cashout
216240
'''
217241
if self.debug:
218-
print("setting up auto bet")
242+
logger.debug("setting up auto bet")
219243

220244
if self.click_button(vars.bet_type_button) is False:
221245
if self.debug:
222-
print("could not click bet type button")
246+
logger.debug("could not click bet type button")
223247
return False
224248
if self.click_button(vars.auto_cashout_button) is False:
225249
if self.debug:
226-
print("could not click auto cashout button")
250+
logger.debug("could not click auto cashout button")
227251
return False
228252

229253

@@ -232,22 +256,22 @@ def place_bet(self,amount, multiplier):
232256
place bet with amount and multiplier
233257
'''
234258
if self.debug:
235-
print(f"setting bet amount to {amount} at multiplier {multiplier}")
259+
logger.debug(f"setting bet amount to {amount} at multiplier {multiplier}")
236260

237261

238262
if self.send_keys(vars.bet_amount_input_box, str(amount)) is False:
239263
if self.debug:
240-
print("could not set bet amount")
264+
logger.debug("could not set bet amount")
241265
return False
242266

243267
if self.send_keys(vars.multiplier_input_box, str(multiplier)) is False:
244268
if self.debug:
245-
print("could not set multiplier")
269+
logger.debug("could not set multiplier")
246270
return False
247271

248272
if self.click_button(vars.place_bet_button) is False:
249273
if self.debug:
250-
print("could not click place bet button")
274+
logger.debug("could not click place bet button")
251275
return False
252276

253277
return True

aviator/vars.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@
2424
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'
2525

2626
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'
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'
28+
29+
30+
#disconnected
31+
32+
disconnected_warning = '/html/body/app-root/app-disconnect-message/div/div[2]/div'

0 commit comments

Comments
 (0)