-
Notifications
You must be signed in to change notification settings - Fork 0
/
excelbot.py
240 lines (221 loc) · 7.85 KB
/
excelbot.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
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
from datetime import datetime
import time
import pyautogui
import random
from os.path import exists
import json
import logging
import pyperclip
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import ssl
#czas
now = datetime.now()
w1 = str(now).replace(" ","--")
w2 = str(w1).replace(":","-")
teraz = str(w2).replace(".","-")+".log"
#logging
logging.basicConfig(filename=teraz, level=logging.INFO)
logging.info("starting")
logging.info(now)
#disclaimer
logging.info("I am not responsible for any consequences that using this software may bring upon you. Have fun! ;)")
print("I am not responsible for any consequences that using this software may bring upon you. Have fun! ;)")
#sprawdzenie,czy jest plik konfiguracyjny
file_exists = exists("conf.json")
if file_exists == True:
#pobranie z niegokoordynatow
logging.info("config openned.")
f = open("conf.json")
data = json.load(f)
x_cell = data["cell"][0]
y_cell = data["cell"][1]
x_field = data["field"][0]
y_field = data["field"][1]
x_name= data["name"][0]
y_name = data["name"][1]
guzik = data["button"]
#mailing
if data["email"]==1:
em_host = data["em_host"]
em_user = data["em_user"]
em_password = data["em_password"]
em_recepient = data["em_recepient"]
em_footer = data["em_footer"]
logging.info("config loaded.")
else:
logging.error("no conf.json file!! program stops.")
print("no conf.json file!! program stops.")
exit()
#randomowe wartosci długość pauzy po kazdej akcji
milisek = random.choice(range(10,800))
ms = "0."+str(milisek)
pyautogui.PAUSE = int(float(ms))
logging.info("random pause1 length set at: "+ms)
#globale
base_scroll = 0
totalscroll = 0
edited = []
temat = "ExcelBot finished work."
em_plain = """
EXCELBOT finished work. See the log file for more details.
"""
def wyslij(nad, has, odb, serw, port, suchy, mokry, temat_wiad):
message = MIMEMultipart("alternative")
message["Subject"] = temat_wiad
message["From"] = nad
message["To"] = odb
part1 = MIMEText(suchy, "plain")
part2 = MIMEText(mokry, "html")
message.attach(part1)
message.attach(part2)
context = ssl.create_default_context()
try:
smtpobj = smtplib.SMTP_SSL(serw, port)#context=context, ale na windzie to nie dziala
smtpobj.login(nad, has)
smtpobj.sendmail(nad, odb, message.as_string())
smtpobj.quit()
logging.info("Mail sent successfully. End of execution.")
print("Mail sent successfully. End of execution.")
except smtplib.SMTPException:
logging.error("error in mail sending process!")
print("error in mail sending process!")
#wybor drogi
wybor = input("choose your path: 1 - dots / 2 - message: --> ")
wybor = int(wybor)
print(wybor)
if wybor==1:
#droga kropki
logging.info("the way of the dot has been chosen")
il = input("how many times do you want to loop: --> ")
logging.info("ammount of loops set at: "+il)
for x in range(0, int(il)):
logging.info("start of loop: "+str(x+1)+"/"+str(il))
#opoznienie po ukonczeniu petli
opoz = random.choice(range(12, 180))
if (x+1)/int(il)==1:
logging.info("LAST LOOP.")
print("LAST LOOP.")
opoz = 3
print(str(x+1)+"/"+il)
if totalscroll>=120:
rand1 = random.choice(range(1,2))
if rand1 == 1:
logging.info("scroll > 120 i rand choise 1 -> scrolling +5 units")
pyautogui.scroll(5)
time.sleep(0.2)
if rand1 == 2:
logging.info("scroll > 120 i rand choise 2 -> scrolling -5 units")
pyautogui.scroll(-5)
time.sleep(0.2)
totalscroll=0
if x!=0 and x%7==0:
rand2 = random.choice(range(1,2))
if rand2 == 1:
logging.info("x!=0 i and can be divided by 7 i rand choice 1 -> scrolling -10 units")
pyautogui.scroll(-10)
if rand2 == 2:
logging.info("x!=0 i and can be divided by 7 i rand choice 2 -> scrolling +10 units")
pyautogui.scroll(10)
totalscroll=0
#randomowa wysokosc scrollu
scrl = random.choice(range(-20,50))
#losowy czas trwania ruszania myszką
nr = random.choice(range(1, 3))
pyautogui.moveTo(x_cell,y_cell, duration=nr, tween=pyautogui.easeInOutQuad)
time.sleep(0.4)
pyautogui.scroll(scrl)
time.sleep(0.2)
pyautogui.click()
time.sleep(0.2)
pyautogui.click()
time.sleep(0.2)
pyautogui.moveTo(x_field, y_field, duration=nr, tween=pyautogui.easeInOutQuad)
time.sleep(0.2)
pyautogui.click()
time.sleep(0.2)
pyautogui.write(".", interval=0.06)
time.sleep(0.2)
pyautogui.press("enter")
time.sleep(0.2)
pyautogui.moveTo(x_name,y_name, duration=nr, tween=pyautogui.easeInOutQuad)
time.sleep(0.2)
pyautogui.click()
time.sleep(0.2)
pyautogui.hotkey(guzik, 'c')
time.sleep(0.4)
spot = pyperclip.paste()
edited.append(spot)
time.sleep(0.2)
pyautogui.moveTo(x_cell,y_cell, duration=nr, tween=pyautogui.easeInOutQuad)
time.sleep(0.2)
pyautogui.click()
time.sleep(0.2)
#pyautogui.hotkey('command', 'z')
totalscroll = totalscroll+scrl
logging.info("made changes in: "+spot)
print("made changes in: "+spot)
print("end of loop "+str(x+1)+". delay before next action "+str(opoz))
logging.info("end of loop "+str(x+1)+". delay before next action "+str(opoz))
time.sleep(opoz)
if wybor==2:
#droga wiadomosci
print("the way of the message has been chosen.")
il = input("how many times do you want to loop: --> ")
tekst = input("enter your message: --> ")
for x in range(0, int(il)):
print("loop "+str(x+1)+"/"+il)
if totalscroll>=120:
rand1 = random.choice(range(1,2))
if rand1 == 1:
print("scrolling +20")
pyautogui.scroll(20)
time.sleep(0.2)
if rand1 == 2:
print("scrolling -20")
pyautogui.scroll(-20)
time.sleep(0.2)
totalscroll=0
if x!=0 and x%7==0:
rand2 = random.choice(range(1,2))
if rand2 == 1:
print("scrolling +15")
pyautogui.scroll(-15)
time.sleep(0.2)
if rand2 == 2:
print("scrolling -15")
pyautogui.scroll(15)
time.sleep(0.2)
totalscroll=0
#randomowa wysokosc scrollu
scrl = random.choice(range(-20,50))
#losowy czas trwania ruszania myszką
nr = random.choice(range(1, 3))
pyautogui.moveTo(551,561, duration=nr, tween=pyautogui.easeInOutQuad)
time.sleep(0.2)
pyautogui.scroll(scrl)
time.sleep(0.2)
pyautogui.click()
time.sleep(0.2)
pyautogui.click()
time.sleep(0.2)
pyautogui.write(tekst, interval=0.06)
time.sleep(0.2)
pyautogui.moveRel(30, 30)
time.sleep(0.2)
pyautogui.click()
time.sleep(0.2)
pyautogui.hotkey('command', 'z')
totalscroll = totalscroll+scrl
elements = [f'<li>{e}</li>' for e in edited]
if data["email"]==1:
tresc = "<h1>ExcelBot v.0.6.9</h1><h2>Edited theese cells:</h2><ul>"+"".join(elements)+"</ul><h3>"+em_footer+"</h3>"
logging.info("sending email.")
print("sending email.")
wyslij(em_user, em_password, em_recepient, em_host, 465, em_plain, tresc, temat)
logging.info("end of program execution.")
print("end of program execution.")
if data["email"]==0:
logging.info("end of program execution.")
print("end of program execution.")