-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbot.py
127 lines (102 loc) · 3.42 KB
/
bot.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
import json
import logging
import requests
import sqlite3
import sys
import time
import config
import primeDiceClass as primedice
if len(sys.argv) < 4:
# sys.exit('usage: bot.py <login> <password> <token> <optional tor_port>')
sys.exit('usage: bot.py <login> <password> <token> <optional proxy_host> <optional proxy_port>')
logging.basicConfig(filename='log-' + sys.argv[1] + '.txt', level=logging.INFO, format='[%(asctime)s] %(levelname)s : %(message)s', datefmt='%H:%M:%S')
logging.info("=== Bot is starting, please wait!")
bot = primedice.primedice()
if len(sys.argv) > 5:
bot.setProxy(sys.argv[4], sys.argv[5])
elif len(sys.argv) > 4:
bot.setProxy(sys.argv[4])
while True:
if bot.login(sys.argv[1], sys.argv[2], sys.argv[3]):
break
bot.restartTor()
bet_size = config.base_bet
streak = 0
profit = 0
wins = 0
conn = sqlite3.connect('primedice-' + sys.argv[1] + '.sqlite')
cursor = conn.cursor()
cursor.execute('CREATE TABLE if not exists primedice(id INTEGER PRIMARY KEY, date DATETIME DEFAULT (DATETIME(CURRENT_TIMESTAMP, \'LOCALTIME\')), bet TEXT, streak INT, profit TEXT, balance TEXT)')
conn.commit()
logging.info("=== Game is starting!")
while (bot.bet_count < config.max_bet_number) \
or (bot.balance >= config.min_balance) \
or (bot.balance <= config.max_balance):
try:
if bet_size > bot.balance:
logging.info("Insufficient funds! :( Returning to base bet!")
bet_size = config.base_bet
if bet_size > config.maximum_bet:
logging.info('Exceeded maximum bet size!')
bet_size = config.base_bet
time.sleep(config.wait_time)
bet_feedback = bot.bet(bet_size, config.win_chance, "<")
if not bet_feedback['profit']:
continue
bot.bet_count += 1
streak += 1
profit += bet_feedback['profit']
#drop sqlite logging in favour of python logging it increases the speed 2 times
#cursor.execute("INSERT INTO primedice(bet, streak, profit, balance) VALUES('%s','%s','%s','%s')" % (bet_size, streak, profit, bot.balance))
#conn.commit()
# log json
data = {}
data['date'] = time.strftime("%Y-%m-%d %H:%M:%S")
data['bet'] = bet_size
data['streak'] = streak
data['profit'] = profit
data['balance'] = bot.balance
json_data = json.dumps(data)
print json_data
logging.info(json_data)
if bot.balance >= config.withbal : #auto withdraw comment to disable
bot.withdraw(config.withdrawamount,config.withdrawaddress)
print("success")
if bet_feedback['win']:
bet_size *= config.after_win_multiplier
streak = 0
profit = 0
wins += 1
if wins >= 50:
wins = 0
print bot.seed()
if not bet_size:
bet_size = config.base_bet
bet_size += config.after_win_sum
else:
bet_size *= config.after_loss_multiplier
if not bet_size:
bet_size = bot.base_bet
bet_size += config.after_loss_sum
# exceptions --------------------------------------------------------------
except primedice.CaptchaException:
print '403: CaptchaException'
bot.restartTor()
except primedice.TooManyRequestsException:
print '429: TooManyRequestsException'
bot.restartTor()
except primedice.BadGatewayException:
print '502: BadGatewayException'
bot.restartTor()
except primedice.AnswerNoneException:
print 'AnswerNoneException'
bot.restartTor()
except requests.exceptions.ConnectionError:
print 'ConnectionError'
bot.restartTor()
except requests.exceptions.ReadTimeout:
print 'ReadTimeout'
except AttributeError:
print 'AttributeError'
bot.restartTor()
logging.info('Exit')