Repository navigation
Expand file tree
/
Copy pathfiis.py
More file actions
258 lines (204 loc) · 8.35 KB
/
Copy pathfiis.py
File metadata and controls
258 lines (204 loc) · 8.35 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
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
import pprint
import os
import openpyxl
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import time
from gtts import gTTS
from playsound import playsound
import shutil
import send2trash
path = "C:\\Users\\Usuário\\Desktop"
file = 'fiis.xlsx'
planilha01 = 'Planilha1'
listaFiis = []
original = r'' + str(file)
alvo = r'' + str(path) + '\\' + str(file)
shutil.copyfile(original, alvo)
os.chdir(path)
wb = openpyxl.load_workbook(str(file))
sheet = wb[str(planilha01)]
for i in range(2, 244, 1):
nameStock = sheet.cell(row=i, column=1).value
listaFiis.append(nameStock)
pprint.pprint(listaFiis)
page = webdriver.Chrome(ChromeDriverManager().install())
listaErros = []
dic = {}
x = 1
for i in listaFiis:
i = str(i)
i = i.lower()
i = i.replace('\n', '')
path = 'https://fiis.com.br/' + i
page.get(path)
time.sleep(5)
x = x + 1
print('Iniciando a abertura dos dados do fundo:', i.upper())
print('Através do endereço: ', path)
try:
basic = '//*[@id="quotations--infos-wrapper"]/div[1]/span[2]'
teste = page.find_element_by_xpath(basic).text
except:
print('############################')
print('ATENÇÂO! ATENÇÂO! ATENÇÂO!')
print('############################')
print('Tivemos um erro com o fundo:', i.upper())
print('O endereço de acesso é', path)
print(' ')
print(' ')
listaErros.append(path)
dic.update({str(path): x})
else:
print('Capiturando dados do fundo...')
# Cotação Atual
basic = '//*[@id="quotations--infos-wrapper"]/div[1]/span[2]'
download = page.find_element_by_xpath(basic).text
sheet.cell(row=x, column=13).value = download
wb.save(str(file))
# Variação
# basic = '//*[@id="quotations--infos-wrapper"]/div[1]/div'
# download = page.find_element_by_xpath(basic).text
# sheet.cell(row=k, column=14).value = download
# wb.save(str(file))
# endereço dos dados
sheet.cell(row=x, column=15).value = path
wb.save(str(file))
# Administrador
basic = '//*[@id="informations--admin"]/div[1]/div[2]/span[1]'
download = page.find_element_by_xpath(basic).text
sheet.cell(row=x, column=16).value = download
wb.save(str(file))
# Telefone
basic = '//*[@id="informations--admin"]/div[2]/div[1]/div[2]/span[2]'
download = page.find_element_by_xpath(basic).text
sheet.cell(row=x, column=17).value = download
wb.save(str(file))
# e-mail
basic = '//*[@id="head--card"]/div[2]/div[2]/div[2]/div[2]/span[2]/a'
download = page.find_element_by_xpath(basic).text
sheet.cell(row=x, column=18).value = download
wb.save(str(file))
# Site
basic = '//*[@id="head--card"]/div[2]/div[2]/div[3]/div[2]/span[2]/a'
download = page.find_element_by_xpath(basic).text
sheet.cell(row=x, column=19).value = download
wb.save(str(file))
# Nome no pregão, Tipo do FII, Tipo AMBIMA, REGSITRO CVM
for j, z in zip(range(1, 5, 1), range(2, 6, 1)):
basic = '//*[@id="informations--basic"]/div[1]/div[' + str(j) + ']/span[2]'
download = page.find_element_by_xpath(basic).text
sheet.cell(row=x, column=z).value = download
wb.save(str(file))
# Nº de Cotas, Número de cotistas, CNPJ
for j, z in zip(range(1, 4, 1), range(6, 9, 1)):
basic = '//*[@id="informations--basic"]/div[2]/div[' + str(j) + ']/span[2]'
download = page.find_element_by_xpath(basic).text
sheet.cell(row=x, column=z).value = download
wb.save(str(file))
#
for j, z in zip(range(1, 5, 1), range(9, 14, 1)):
basic = '//*[@id="informations--indexes"]/div[' + str(j) + ']/span[1]'
download = page.find_element_by_xpath(basic).text
sheet.cell(row=x, column=z).value = download
wb.save(str(file))
print('Dados capiturados e aparentemente tudo ok')
print('Total de fundos varificados:', (x - 1))
print(' ')
print('Endereços com problema de acesso aos dados: ', )
pprint.pprint(listaErros)
print(' ')
print('Endereço / Linha para inserir os dados', )
pprint.pprint(dic)
print(' ')
print('A seguir iniciaremos uma novo acesso às páginas que apresentaram erro:')
print('############################')
print('############################')
print('')
print('')
listaErros02 = []
dic02 = {}
# tratando erros
for v, k in dic.items():
print('Vamos testar o acesso à página: ', v)
try:
page.get(v)
time.sleep(5)
basic = '//*[@id="quotations--infos-wrapper"]/div[1]/span[2]'
teste = page.find_element_by_xpath(basic).text
except:
print('Continuamos tendo um erro com o fundo: ', v)
print('O endereço de acesso é', path)
listaErros02.append(v)
dic02.update({str(path): x})
else:
print('O endereço abaixo não está com problemas:')
print(v)
print('Capiturando os dados...')
# Cotação Atual
basic = '//*[@id="quotations--infos-wrapper"]/div[1]/span[2]'
download = page.find_element_by_xpath(basic).text
sheet.cell(row=k, column=13).value = download
wb.save(str(file))
# Variação
# basic = '//*[@id="quotations--infos-wrapper"]/div[1]/div'
# download = page.find_element_by_xpath(basic).text
# sheet.cell(row=k, column=14).value = download
# wb.save(str(file))
# endereço dos dados
sheet.cell(row=k, column=15).value = v
wb.save(str(file))
# Administrador
basic = '//*[@id="head--card"]/div[2]/div[1]/div[2]/span[2]'
download = page.find_element_by_xpath(basic).text
sheet.cell(row=k, column=16).value = download
wb.save(str(file))
# Telegone
basic = '//*[@id="head--card"]/div[2]/div[2]/div[1]/div[2]/span[2]'
download = page.find_element_by_xpath(basic).text
sheet.cell(row=k, column=17).value = download
wb.save(str(file))
# e-mail
basic = '//*[@id="head--card"]/div[2]/div[2]/div[2]/div[2]/span[2]/a'
download = page.find_element_by_xpath(basic).text
sheet.cell(row=k, column=18).value = download
wb.save(str(file))
# Site
basic = '//*[@id="head--card"]/div[2]/div[2]/div[3]/div[2]/span[2]/a'
download = page.find_element_by_xpath(basic).text
sheet.cell(row=k, column=19).value = download
wb.save(str(file))
# Nome no pregão, Tipo do FII, Tipo AMBIMA, REGSITRO CVM
for j, z in zip(range(1, 5, 1), range(2, 6, 1)):
basic = '//*[@id="informations--basic"]/div[1]/div[' + str(j) + ']/span[2]'
download = page.find_element_by_xpath(basic).text
sheet.cell(row=k, column=z).value = download
wb.save(str(file))
# Nº de Cotas, Número de cotistas, CNPJ
for j, z in zip(range(1, 4, 1), range(6, 9, 1)):
basic = '//*[@id="informations--basic"]/div[2]/div[' + str(j) + ']/span[2]'
download = page.find_element_by_xpath(basic).text
sheet.cell(row=k, column=z).value = download
wb.save(str(file))
# Dividend Yield, Último Rendimento, Patrimônio Liquido, Valor patrimonial/Cota
for j, z in zip(range(1, 5, 1), range(9, 14, 1)):
basic = '//*[@id="informations--indexes"]/div[' + str(j) + ']/span[1]'
download = page.find_element_by_xpath(basic).text
sheet.cell(row=k, column=z).value = download
wb.save(str(file))
print('Dados capiturados e aparentemente tudo ok')
print(' ')
print('Relatório de erros')
print('Endereços com problema de acesso aos dados: ', )
pprint.pprint(listaErros02)
print(' ')
print('Endereço / Linha para inserir os dados', )
pprint.pprint(dic02)
print(' ')
print('Favor, rever os erros')
print('Tente verficar se os endereços listados estão com os digitos corretos')
num_de_cell = str('Danilo, Finalizei a coleta dos dados de fundo imobiliários')
tts = gTTS(num_de_cell, lang='pt-br')
tts.save('num_de_cell.mp3') # Salva o arquivo de audio
playsound('num_de_cell.mp3')
send2trash.send2trash('nome_arquivo.mp3')