-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.py
202 lines (168 loc) · 7.3 KB
/
App.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
from tkinter import *
from GlobalConfig import GlobalConfig
from login import Login
from send_registers import send_rg_in_base
from undoing_change import undoing
from scan_informais_in_system import scan
from utils import (
alter_data_the_itens,
convert_url,
file_is_exists,
create_json,
insert_arq_log,
reading_json,
)
from reading_xml import update_xlsx
from file_monitoration import plan_is_change
from create_boxs import add_item
from time import sleep
from scrapping_boxs import scrapping_b
from file_monitoration import folder_is_change
from upload import conf_file_upload, up_files
from SituationView import SituationView
import speedtest
from time import time
# Code ..
class App:
def start(self):
self.conf = GlobalConfig()
if not self.conf.is_error():
self.root = Tk()
self.app = SituationView(self.root)
try:
self.boxs = file_is_exists(convert_url("./config/boxs.json"))
except:
self.boxs = False
try:
change, self.foldrs = folder_is_change()
except:
change = False
if not self.boxs or plan_is_change(self.conf) or change:
self.app.situation("Esperando página carregar ...")
try:
self.lg = Login(self.conf.getUrlBase(),self.conf.getUser(),self.conf.getPassword(), self.conf.getClient(), False, self.app)
except Exception as erro:
insert_arq_log(f'{erro}')
self.app.situation(f'Error: {erro.__cause__}')
self.app.buttonExit()
else:
if self.lg.is_logout():
self.app.situation("Login feito com sucesso")
self.app.situation("Esperando página carregar ...")
try:
if self.lg.authentication_validation():
self.app.situation("Página carregada")
if not self.boxs:
self.box_change()
if plan_is_change(self.conf):
self.plan_change()
if change:
self.send_rg()
except Exception as erro:
insert_arq_log(f'{erro}')
self.app.situation(f'Error: {erro.__cause__}')
self.lg.driver.close()
self.app.buttonExit()
else:
self.lg.driver.close()
self.app.situation("Conexão fechada")
sleep(2)
self.app.ext()
else:
self.app.situation("Nenhuma mudança encontrada!!!")
sleep(3)
self.app.ext()
self.root.mainloop()
def box_change(self):
self.app.situation("Começando a criação dos arquivos de configuração!!")
self.conf.mapping_boxs(self.lg, self.app)
def plan_change(self):
self.alters = list()
try:
self.app.situation("Lendo arquivos de configuração ...")
dt = reading_json(convert_url('./config/boxs'))
try:
if len(dt):
dt = dt[(len(dt))-1]
if len(dt['boxs']):
try:
dt['boxs'] = dt['boxs'][(len(dt['boxs']))-1]
except Exception as error:
insert_arq_log(f'App: Row 102 {error} ; Val: {dt}')
else:
dt['boxs'] = {
"index" : False
}
else:
dt = {}
except Exception as error:
insert_arq_log(f'App: Row 106: {error} ; Val: {dt}')
self.app.situation("Preparando tudo para o envio ...")
try:
upl = update_xlsx(dt)
except Exception as error:
insert_arq_log(f'App: Row 115: {error}')
self.app.situation(f'Preparando para enviar {len(upl)} caixas')
for up in upl:
resul = add_item(self.lg, up, self.app)
if resul['Error']:
self.alters.append(resul['link'])
insert_arq_log(f'App: Row 126: {resul}')
undoing(self.lg,resul, self.app)
break
else:
self.alters.append(resul['link'])
except Exception as error:
insert_arq_log(f'App: Row 123: {error}')
finally:
if len(self.alters):
self.app.situation(f'Mapiando as informações ...')
lista_values = scrapping_b(self.lg, self.alters)
self.app.situation("Mapiando elementos ...") if self.app else print("Mapiando elementos ...")
dt = scan(self.lg, lista_values, self.app)
self.app.situation("Finalizado o mapiamento de elementos ...") if self.app else print("Finalizado o mapiamento de elementos ...")
self.app.situation(f'Escrevendo mudanças') if self.app else print(f'Escrevendo mudanças')
origen = reading_json(convert_url('./config/boxs'))
_new_dic = alter_data_the_itens(origen, dt)
self.conf.configuration_arq_create(_new_dic, self.app) if self.app else self.conf.configuration_arq_create(_new_dic)
self.app.situation(f'Finalizado') if self.app else print(f'Finalizado')
def send_rg(self):
self.app.situation(f'Preparando para adicionar registros no sistema ...')
try:
send_rg_in_base(self.lg, self.foldrs, self.app)
except Exception as error:
insert_arq_log(f'{error}')
self.app.situation(f'Mapiando as informações ...')
self.conf.mapping_boxs(self.lg, self.app)
self.app.situation(f'Finalizado')
self.lg.driver.close()
self.app.buttonExit()
else:
try:
while True:
self.app.situation(f'Configurando arquivo para upload...')
conf_file_upload()
self.app.situation(f'Verificando velocidade da internet ... ')
st = speedtest.Speedtest()
st.get_best_server()
bytes_val = st.upload()
Megabits = bytes_val/1048576
MegaBytes = Megabits/8
self.app.situation(f'Velocidade da internet {MegaBytes:.2f}... ')
self.app.situation(f'Começando upload..')
if up_files(self.lg, MegaBytes, self.app):
break
except Exception as error:
insert_arq_log(f'{error}')
self.app.situation(f'Mapiando as informações ...')
self.conf.mapping_boxs(self.lg, self.app)
self.lg.driver.close()
self.app.buttonExit()
try:
start = time()
init = App()
init.start()
except Exception as error:
insert_arq_log(f'{error}')
finally:
insert_arq_log(f'Execucao em: {(((time() - start))/60):.2f}m')