forked from songdoyouho/money
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulation.py
More file actions
202 lines (173 loc) · 6.15 KB
/
simulation.py
File metadata and controls
202 lines (173 loc) · 6.15 KB
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
from PIL import ImageGrab, ImageChops, Image
import numpy as np
import cv2
import win32gui
import pyautogui
import time
import sys
import json
import secret
keys = secret.keys()
from linebot import LineBotApi
from linebot.models import TextSendMessage
my_user_id = "U4a163602a7d66b0494cc38f4824d4d44"
line_bot_api = LineBotApi(keys.line_api_50)
from datetime import datetime
pyautogui.FAILSAFE = True
hwnd = win32gui.FindWindow(None, '京彩 - Google Chrome')
try :
left_x, left_y, right_x, right_y = win32gui.GetWindowRect(hwnd)
except :
print("no catch!")
def correct_or_not(flag, open_result, i_vote, rate):
print("correct or not")
if open_result == i_vote:
flag = True
rate = 1
print('correct!!!')
else:
flag = False
rate *= 2
print('fail!!!')
return flag, rate
def update_result(color_map, open_result):
#print("update result")
img = ImageGrab.grab(bbox = (left_x, left_y, right_x, right_y))
img_np = np.array(img)
color_want = img_np[255, 648, :] # y , x
color_want = color_want.tolist()
true_num = color_map.index(color_want) + 1
print('open number :',true_num) # 1=單 2=雙
# get open_result
if true_num % 2 == 0:
open_result = False
else:
open_result = True
time.sleep(1)
return open_result, true_num
def move_to_vote(flag, open_result, i_vote, rate):
print('vote time!')
if open_result == True: #單
i_vote = open_result
print('vote single')
pyautogui.moveTo(780, 600) # 單
pyautogui.click()
else:
i_vote = open_result
print('vote double')
pyautogui.moveTo(995, 600) # 雙
pyautogui.click()
time.sleep(1)
pyautogui.moveTo(1245, 250) # rate
pyautogui.click()
pyautogui.press('backspace')
time.sleep(1)
pyautogui.typewrite(str(rate))
print('vote :', rate*5)
pyautogui.moveTo(1256, 385) # confirm
pyautogui.click()
pyautogui.moveTo(565, 490)
time.sleep(1)
pyautogui.click()
pyautogui.moveTo(685, 470)
time.sleep(1.5)
pyautogui.click()
return i_vote
def refresh():
pyautogui.moveTo(1090, 252)
pyautogui.click()
def vote_loop(win_count):
# start vote loop
time_flag = True
vote_flag = True # 有沒有猜對
vote_open_result = True # 單
vote_i_vote = True # 單
vote_rate = 1
vote_yes_count = 0
vote_no_count = 0
while time_flag:
now = datetime.now()
if now.second == 10: # 五秒時開始下注
print('-----------------------------------------------------')
print(now.year, now.month, now.day, now.hour, now.minute)
print('start bot!')
refresh()
time.sleep(2)
vote_open_result, vote_true_num = update_result(color_map, vote_open_result)
vote_flag, vote_rate = correct_or_not(vote_flag, vote_open_result, vote_i_vote, vote_rate)
# 統計有沒有中, 有中把fail歸零
if vote_flag == True:
vote_yes_count += 1
print('success :', vote_yes_count)
vote_no_count = 0
else:
vote_no_count += 1
print('fail :', vote_no_count)
# send line to me
send_sth = str(now.year)+ ':' +str(now.month)+ ':' +str(now.day)+ ':' +str(now.hour)+ ':' +str(now.minute)
if vote_flag == True:
if vote_i_vote == True:
send_result = send_sth + '\n' + 'win '+ str(rate*5) + 'NTD\n' + 'open number:' + str(vote_true_num) + '\n' + 'voted single' + '\n' + 'success:' + str(vote_yes_count)
else:
send_result = send_sth + '\n' + 'win '+ str(rate*5) + 'NTD\n' + 'open number:' + str(vote_true_num) + '\n' + 'voted double' + '\n' + 'success:' + str(vote_yes_count)
else:
if vote_i_vote == True:
send_result = send_sth + '\n' + 'lose '+ str(int(rate/2*5)) + 'NTD\n' + 'open number:' + str(vote_true_num) + '\n' + 'voted single' + '\n' + 'fail:' + str(vote_no_count)
else:
send_result = send_sth + '\n' + 'lose '+ str(int(rate/2*5)) + 'NTD\n' + 'open number:' + str(vote_true_num) + '\n' + 'voted double' + '\n' + 'fail:' + str(vote_no_count)
line_bot_api.push_message(my_user_id, TextSendMessage(send_result))
# check end
if vote_yes_count == win_count:
time_flag = False
continue
if vote_no_count == 8:
time_flag = False
continue
# simulation
# voting
#vote_i_vote = move_to_vote(vote_flag, vote_open_result, vote_i_vote, vote_rate)
else:
time.sleep(0.5)
# 整點開始下注,45秒時封盤
# 算時間
# main
# init 上一次的結果是單 下單數 一倍
flag = True
open_result = True # 單
i_vote = True # 單
rate = 1
yes_count = 0
no_count = 0
color_map = [[148, 161, 161], [250, 0, 78], [255, 70, 66], [247, 164, 92], [0, 211, 130], [8, 193, 228], [169, 38, 225], [57, 115, 224], [102, 115, 137], [54, 54, 54]]
# init
my_money = 10000
now = datetime.now()
refresh()
time.sleep(2)
open_result, true_num = update_result(color_map, open_result)
last_open = open_result
last_num = true_num
# start loop
while True:
now = datetime.now()
if now.second == 10: # 五秒時開始下注
if no_count == 8:
no_count = 0
line_bot_api.push_message(my_user_id, TextSendMessage('沒中8次!\n開始下注!'))
#vote_loop(100)
#break
else:
refresh()
time.sleep(2)
open_result, true_num = update_result(color_map, open_result)
# 統計有沒有中, 有中把fail歸零
if last_open == open_result: # 上一次開的跟這一次一樣
yes_count += 1
no_count = 0
else:
no_count += 1
line_bot_api.push_message(my_user_id, TextSendMessage('沒中'+str(no_count)+'次!'))
last_open = open_result
last_num = true_num
else:
time.sleep(0.5)