/
main.py
486 lines (409 loc) · 17 KB
/
main.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
# -*- coding: utf-8 -*-
"""
- O item 1 tem que ser administracao Local
- Salvar como valor tudo dentro da aba Orçamento e Calculo e apagar as outras abas
-
@author: felipebrandao
"""
linhaInicial = 62
linhaUltima = 72
colunaInicial = 13
#cposName = 'CPOS 178'
time0 = 1
time1 = 2#float ( input("obs-siconv em primeiro plano, excel em segundo, celula do codigo marcado, digite o tempo lento") )
time2 = 5#float( input("digite o tempo rapido") )
n_frentes = 4 #number of frentes de obra
item_times = 1#int( input("digite a quantidade de itens sinapi"))
bdi1 = "24,22" #16,79 #24,23
bdi2 = "16,78"
import pandas as pd
import pyautogui
#import win32clipboard
import matplotlib.pyplot as plt
from PIL import Image
from PIL import ImageChops
import time
import xerox
#import win32clipboard
#import locale
#locale.setlocale(locale.LC_ALL, 'pt_BR.UTF-8')
orc = pd.read_excel('planilha.xlsx', sheet_name='ORÇAMENTO', encoding='latin-1')
calc = pd.read_excel('planilha.xlsx', sheet_name='CÁLCULO')
n_evento = orc.iloc[linhaInicial-2, colunaInicial+1 ].split('.')
n_evento = int(n_evento[1])
def equals(first_img, second_img):
"""
Identifies if first_img and second_img are identical to each other.
Args:
first_img: a PIL image object of the original image
second_img: a PIL image object of the modified image
Returns: A boolean stating whether or not the two images are identical, True means they are identical.
"""
if first_img is None or second_img is None:
return False
diff = ImageChops.difference(first_img, second_img)
if diff.getbbox() != None:
return False
else:
diff = None
return True
def cadastroItem(is_SINAPI,primeiraVez,codigo,descricao, unidade, precoUnitario, bdi, quantidades):
time.sleep(2)
pyautogui.PAUSE = time0
if primeiraVez == 1:
pyautogui.keyDown('alt')
pyautogui.hotkey('tab')
pyautogui.keyUp('alt')
#pyautogui.confirm('Prosseguir0')
pyautogui.hotkey('tab')
pyautogui.hotkey('enter')
pyautogui.PAUSE = 2
#image = pyautogui.locateOnScreen('detect_my_job1.png')
#while image != None:
# print('prosseguir 1')
# image = pyautogui.locateOnScreen('detect_my_job.png')
time.sleep(2)
#im = pyautogui.screenshot('test1-1.png', region=(660,560, 80, 40))
#im = pyautogui.screenshot('test1-1-trabalho.png', region=(670,490, 80, 30))
im = pyautogui.screenshot('test1-1-trabalho.png', region=(670,460, 80, 30))
imgplot = plt.imshow(im)
plt.show()
im2 = Image.open("aguarde_trabalho.png")
equalImages = equals(im, im2)
print(equalImages)
while equalImages == True:
im = pyautogui.screenshot('test1-2-trabalho.png', region=(670,460, 80, 30))
equalImages = equals(im, im2)
print('cadastro item stop 1')
#pyautogui.confirm('Prosseguir1')
#pyautogui.PAUSE = time2
pyautogui.hotkey('right')
pyautogui.PAUSE = 2
im = pyautogui.screenshot('test2-1-trabalho.png', region=(670,490, 80, 30))
equalImages = equals(im, im2)
while equalImages == True:
im = pyautogui.screenshot('test.png', region=(670,490, 80, 30))
equalImages = equals(im, im2)
print('cadastro item stop 2')
#pyautogui.confirm('Prosseguir2')
pyautogui.hotkey('tab')
pyautogui.PAUSE = time0
#pyautogui.hotkey('down')
pyautogui.typewrite(str(n_evento), interval=0.001)
if n_evento >= 10:
time.sleep(3)
pyautogui.typewrite(str(n_evento), interval=0.001)
pyautogui.PAUSE = time1
pyautogui.hotkey('tab')
pyautogui.PAUSE = 0.25
pyautogui.hotkey('tab')
pyautogui.PAUSE = 2
if is_SINAPI == 1: # eh SINAPI
pyautogui.hotkey('s')
pyautogui.PAUSE = 1
pyautogui.hotkey('tab')
pyautogui.hotkey('enter')
im = pyautogui.screenshot('test2.png', region=(970,495, 90, 25))
imgplot = plt.imshow(im)
plt.show()
imlupapesquisar = Image.open("lupaPesquisar.png")
equalImages = equals(im, imlupapesquisar)
#while equalImages == False:
im = pyautogui.screenshot('test2.png', region=(970,495, 200, 100))
# equalImages = equals(im, imlupapesquisar)
# print(equalImages)
#pyautogui.confirm('Prosseguir - clicou na lupa?')
pyautogui.hotkey('shift','tab')
pyautogui.hotkey('left')
pyautogui.hotkey('tab')
##pyautogui.keyDown('alt')
##if primeiraVez == 1:
## pyautogui.hotkey('tab')
##pyautogui.hotkey('tab')
##pyautogui.keyUp('alt')
#copia e cola o CODIGO
##pyautogui.hotkey('ctrl','c') #copia e cola o CODIGO
##pyautogui.hotkey('right')
##pyautogui.hotkey('right')
##pyautogui.hotkey('right')
##pyautogui.hotkey('right')
##pyautogui.keyDown('alt')
##pyautogui.hotkey('tab')
##pyautogui.keyUp('alt')
pyautogui.PAUSE = 0.5
pyautogui.typewrite( codigo, interval=0.1)
#pyautogui.hotkey('ctrl','v')
pyautogui.hotkey('tab')
pyautogui.hotkey('enter')
pyautogui.PAUSE = 2
time.sleep(3)
#pyautogui.confirm('Prosseguir - PRONTO PARA APERTAR ENTER?')
pyautogui.hotkey('enter')
pyautogui.hotkey('tab')
pyautogui.hotkey('tab')
pyautogui.hotkey('tab')
pyautogui.hotkey('enter')
pyautogui.PAUSE = 2
#copia e cola o CUSTO UNITÁRIO
##pyautogui.keyDown('alt')
##pyautogui.hotkey('tab')
##pyautogui.keyUp('alt')
time.sleep(3)
#pyautogui.confirm('Prosseguir - NO EXCEL PRONTO COPIAR CUSTO?')
##pyautogui.hotkey('ctrl','c')
#pyautogui.confirm('Prosseguir - COPIOU O CUSTO?')
##pyautogui.keyDown('alt')
##pyautogui.hotkey('tab')
##pyautogui.keyUp('alt')
pyautogui.typewrite( precoUnitario, interval=0.1)
##pyautogui.hotkey('ctrl','v')
if is_SINAPI == 0: #nao eh SINAPI, eh CPOS, SIURB,...
pyautogui.hotkey('o')
pyautogui.PAUSE = time2
pyautogui.hotkey('tab')
pyautogui.PAUSE = 0.25
#copy and paste CODIGO
##pyautogui.keyDown('alt')
##if primeiraVez == 1:
## pyautogui.hotkey('tab')
##pyautogui.hotkey('tab')
##pyautogui.keyUp('alt')
##pyautogui.hotkey('ctrl','c')
##pyautogui.keyDown('alt')
##pyautogui.hotkey('tab')
##pyautogui.keyUp('alt')
pyautogui.PAUSE = 0.5
#pyautogui.hotkey('tab')
#pyautogui.keyDown('alt')
#pyautogui.confirm('Prosseguir3 - pronto para colar o codigo')
pyautogui.typewrite( codigo, interval=0.1)
##pyautogui.hotkey('ctrl','v')
#fim do copia e cola
pyautogui.hotkey('tab')
#copy and paste
#descricao
#pyautogui.confirm('Prosseguir3-1 - o codigo deveria ir para o excel e copiar a descricao')
pyautogui.PAUSE = 0.25
##pyautogui.keyDown('alt')
##pyautogui.hotkey('tab')
#pyautogui.hotkey('tab')
##pyautogui.keyUp('alt')
##pyautogui.hotkey('right')
##pyautogui.hotkey('ctrl','c')
##pyautogui.keyDown('alt')
##pyautogui.hotkey('tab')
##pyautogui.keyUp('alt')
#pyautogui.hotkey('tab')
#pyautogui.typewrite( descricao, interval=0.1)
xerox.copy(descricao)
xerox.paste()
pyautogui.hotkey('ctrl','v')
#fim do copia e cola
#pyautogui.hotkey('tab')
#copia e cola a UNIDADE
##pyautogui.keyDown('alt')
##pyautogui.hotkey('tab')
##pyautogui.keyUp('alt')
##pyautogui.hotkey('right')
##pyautogui.hotkey('ctrl','c')
#OBS: criar mecanismo para analisar termo copiado
##win32clipboard.OpenClipboard()
##unidade = win32clipboard.GetClipboardData()
##print(unidade)
##win32clipboard.CloseClipboard()
#pyautogui.confirm('Prosseguir3-1-1 - copiou a unidade?')
##pyautogui.keyDown('alt')
##pyautogui.hotkey('tab')
##pyautogui.keyUp('alt')
pyautogui.PAUSE = 2
pyautogui.hotkey('tab')
pyautogui.hotkey('space')
pyautogui.typewrite(unidade, interval=0.1)
#pyautogui.confirm('Prosseguir3-2 - tudo certo com a unidade?')
pyautogui.PAUSE = 1
#UNIDADE
#pyautogui.confirm('Prosseguir3-2 COLOCAR UNIDADE')
#pyautogui.typewrite(unidade, interval=0.1)
pyautogui.hotkey('tab')
#copy and paste
#custo referencia
pyautogui.PAUSE = 0.25
##pyautogui.keyDown('alt')
##pyautogui.hotkey('tab')
##pyautogui.keyUp('alt')
pyautogui.PAUSE = 0.25
#pyautogui.hotkey('right')
##pyautogui.hotkey('right')
##pyautogui.hotkey('right')
##pyautogui.hotkey('ctrl','c')
##pyautogui.keyDown('alt')
##pyautogui.hotkey('tab')
##pyautogui.keyUp('alt')
pyautogui.PAUSE = time1
#pyautogui.hotkey('tab')
pyautogui.typewrite(precoUnitario, interval=0.1)
##pyautogui.hotkey('ctrl','v')
#fim do copia e cola
pyautogui.hotkey('tab')
#custo unitario
##pyautogui.hotkey('ctrl','v')
pyautogui.typewrite(precoUnitario, interval=0.1)
#COMUM PARA TANTO SINAPI COMO PARA AS OUTRAS TABELAS
pyautogui.PAUSE = 1
pyautogui.hotkey('tab')
#pyperclip.copy(bdi)
#pyperclip.paste()
xerox.copy(bdi)
pyautogui.hotkey('ctrl','v')
#pyautogui.typewrite( bdi, interval=1)
pyautogui.PAUSE = 0.25
#com eventos
pyautogui.hotkey('tab')
#pyautogui.hotkey('down')
pyautogui.typewrite(str(n_evento), interval=0.1)
#fim com eventos
#copy and paste
#quantidade (COM EVENTOS)
pyautogui.PAUSE = 0.25
pyautogui.hotkey('tab')
##pyautogui.keyDown('alt')
##pyautogui.hotkey('tab')
##pyautogui.keyUp('alt')
pyautogui.PAUSE = 0.25
#pyautogui.hotkey('left') antes pegava da propria PO
##pyautogui.hotkey('ctrl','pagedown') #muda para a aba CALCULO
##pyautogui.hotkey('ctrl','c')
pyautogui.PAUSE = 1
for x in range (1,n_frentes+1):
#pyautogui.typewrite(quantidades[x-1], interval=0.1)
time.sleep(2)
xerox.copy(quantidades[x-1])
pyautogui.hotkey('ctrl','v')
pyautogui.hotkey('tab')
##pyautogui.keyDown('alt')
##pyautogui.hotkey('tab')
##pyautogui.keyUp('alt') #muda para o excel
##if x != n_frentes+1:
## pyautogui.hotkey('right')
## pyautogui.hotkey('ctrl','c')
## print(x)
#if x == (n_frentes):
print('aqui')
##pyautogui.hotkey('down')
##for y in range (1, n_frentes+1): #deixa o cursor na primeira frente do proximo item
## pyautogui.hotkey('left')
##pyautogui.hotkey('ctrl', 'pageup') #volta para a aba PO
##pyautogui.hotkey('down')
##pyautogui.hotkey('left')
##pyautogui.hotkey('left')
##pyautogui.hotkey('left')
##pyautogui.hotkey('left') #deixa o cursor no codigo do proximo item na PO
##pyautogui.keyDown('alt')
##pyautogui.hotkey('tab')
##pyautogui.keyUp('alt') #muda para o siconv
pyautogui.hotkey('tab')
pyautogui.hotkey('tab')
pyautogui.hotkey('enter') #aperta salvar no siconv
im = pyautogui.screenshot('test1-1-trabalho.png', region=(670,490, 80, 30))
imgplot = plt.imshow(im)
plt.show()
im2 = Image.open("aguarde_trabalho.png")
equalImages = equals(im, im2)
print(equalImages)
while equalImages == True:
im = pyautogui.screenshot('test1-2-trabalho.png', region=(670,490, 80, 30))
equalImages = equals(im, im2)
print('cadastro item stop 1')
def cadastroMacroItem(primeiraVez,descricaoMacro):
time.sleep(2)
pyautogui.PAUSE = 1
if primeiraVez == 1:
pyautogui.keyDown('alt')
pyautogui.hotkey('tab')
pyautogui.keyUp('alt')
pyautogui.hotkey('tab')
pyautogui.hotkey('enter')
time.sleep(2)
im = pyautogui.screenshot('test1-1-trabalho.png', region=(670,490, 80, 30))
imgplot = plt.imshow(im)
plt.show()
im2 = Image.open("aguarde_trabalho.png")
equalImages = equals(im, im2)
print(equalImages)
while equalImages == True:
im = pyautogui.screenshot('test1-2-trabalho.png', region=(670,490, 80, 30))
equalImages = equals(im, im2)
print('cadastro item stop 1')
#pyautogui.confirm('Prosseguir1')
time.sleep(2)
pyautogui.hotkey('space') #seleciona macroservico
pyautogui.hotkey('tab')
pyautogui.hotkey('tab')
##pyautogui.keyDown('alt') #muda para o excel para copiar
#e colar nome do macroservico
##pyautogui.hotkey('tab')
##pyautogui.hotkey('tab')
##pyautogui.keyUp('alt')
##pyautogui.hotkey('right')
##pyautogui.hotkey('ctrl', 'c')
##pyautogui.hotkey('down')
##pyautogui.hotkey('left')
##pyautogui.hotkey('ctrl', 'pagedown')
##pyautogui.hotkey('down')
##pyautogui.hotkey('ctrl', 'pageup')
##pyautogui.keyDown('alt')
##pyautogui.hotkey('tab')
##pyautogui.keyUp('alt')
##pyautogui.hotkey('ctrl', 'v')
#######
##pyautogui.typewrite(descricaoMacro, interval=0.1)
xerox.copy(descricaoMacro)
xerox.paste()
pyautogui.hotkey('ctrl','v')
pyautogui.hotkey('tab')
pyautogui.hotkey('tab')
pyautogui.hotkey('enter')
im = pyautogui.screenshot('test1-1-trabalho.png', region=(670,490, 80, 30))
imgplot = plt.imshow(im)
plt.show()
im2 = Image.open("aguarde_trabalho.png")
equalImages = equals(im, im2)
print(equalImages)
while equalImages == True:
im = pyautogui.screenshot('test1-2-trabalho.png', region=(670,490, 80, 30))
equalImages = equals(im, im2)
print('cadastro macroitem stop 1')
#### MAIN
primeiraVez = 1
while linhaInicial <= linhaUltima:
tipoNivel = orc.iloc[linhaInicial-2, colunaInicial ]
if tipoNivel == "Serviço":
tablePrice = orc.iloc[linhaInicial-2, colunaInicial+2 ]
if tablePrice == 'SINAPI' or tablePrice == 'SINAPI-I':
is_SINAPI = 1 # eh SINAPI = 1 ; eh outra tabela = 0;
else:
is_SINAPI = 0 # eh SINAPI = 1 ; eh outra tabela = 0;
codigo = orc.iloc[linhaInicial-2, colunaInicial+3 ]
descricao = orc.iloc[linhaInicial-2, colunaInicial+4 ]
unidade = orc.iloc[linhaInicial-2, colunaInicial+5 ]
precoUnitario = str(orc.iloc[linhaInicial-2, colunaInicial+7 ])
precoUnitario = precoUnitario.replace('.',',')
bdiTipo = orc.iloc[linhaInicial-2, colunaInicial+8 ]
if bdiTipo == "BDI 2":
bdi = bdi2
elif bdiTipo == "BDI 1":
bdi = bdi1
quantidades = []
for i in range(n_frentes):
quantidades.append( str(calc.iloc[linhaInicial-2, colunaInicial+3+i ]) )
quantidades[i] = quantidades[i].replace('.',',')
cadastroItem(is_SINAPI,primeiraVez,codigo,descricao, unidade, precoUnitario, bdi, quantidades)
elif tipoNivel == "Nível 2":
descricaoMacro = orc.iloc[linhaInicial-2, colunaInicial+4 ]
cadastroMacroItem(primeiraVez,descricaoMacro)
#elif tipoNivel == "Nível 3" or tipoNivel == "Nível 4":
linhaInicial = linhaInicial + 1
primeiraVez = 0
n_evento = orc.iloc[linhaInicial-2, colunaInicial+1 ].split('.')
n_evento = int(n_evento[1])
print(linhaInicial)