csc-cia-stne 0.0.68__py3-none-any.whl → 0.0.69__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- csc_cia_stne/google_drive.py +51 -3
- {csc_cia_stne-0.0.68.dist-info → csc_cia_stne-0.0.69.dist-info}/METADATA +1 -1
- {csc_cia_stne-0.0.68.dist-info → csc_cia_stne-0.0.69.dist-info}/RECORD +6 -6
- {csc_cia_stne-0.0.68.dist-info → csc_cia_stne-0.0.69.dist-info}/LICENCE +0 -0
- {csc_cia_stne-0.0.68.dist-info → csc_cia_stne-0.0.69.dist-info}/WHEEL +0 -0
- {csc_cia_stne-0.0.68.dist-info → csc_cia_stne-0.0.69.dist-info}/top_level.txt +0 -0
csc_cia_stne/google_drive.py
CHANGED
@@ -256,9 +256,9 @@ class GoogleDrive:
|
|
256
256
|
except Exception as e:
|
257
257
|
return {"success": False, "result": None, "error": str(e)}
|
258
258
|
|
259
|
-
def
|
259
|
+
def download_google_files(self, file: str, mimeType: str, path: str):
|
260
260
|
"""
|
261
|
-
Obtém o conteúdo de um arquivo armazenado no Google Drive.
|
261
|
+
Obtém o conteúdo de um arquivo armazenado no Google Drive. Aceito somente para extensões Google
|
262
262
|
|
263
263
|
Esta função acessa o Google Drive usando a API e lê os dados do arquivo especificado, retornando-os como um objeto binário de memória (`BytesIO`).
|
264
264
|
|
@@ -281,15 +281,63 @@ class GoogleDrive:
|
|
281
281
|
Dependências:
|
282
282
|
- A função assume a existência de um atributo `self.service` configurado para interagir com a API do Google Drive.
|
283
283
|
"""
|
284
|
+
if not os.path.exists(path):
|
285
|
+
os.makedirs(path)
|
284
286
|
try:
|
285
287
|
request = self.service.files().export_media(
|
286
288
|
fileId=file.get("id"), mimeType=mimeType
|
287
289
|
)
|
290
|
+
file_path = f"{path}{file["name"]}"
|
288
291
|
with open(file["name"], "wb") as f:
|
289
292
|
f.write(request.execute())
|
290
293
|
return {
|
291
294
|
"success": True,
|
292
|
-
"result":
|
295
|
+
"result": file_path,
|
296
|
+
}
|
297
|
+
|
298
|
+
except Exception as e:
|
299
|
+
return {"success": False, "result": None}
|
300
|
+
|
301
|
+
def download_others_files(self, file: str, path: str):
|
302
|
+
"""
|
303
|
+
Obtém o conteúdo de um arquivo armazenado nos seguintes formatos:
|
304
|
+
.xlsx, .pdf, .jpg, etc.
|
305
|
+
|
306
|
+
Esta função acessa o Google Drive usando a API e lê os dados do arquivo especificado, retornando-os como um objeto binário de memória (`BytesIO`).
|
307
|
+
|
308
|
+
Parâmetros:
|
309
|
+
- file (str): Dicionário contendo informações do arquivo no Google Drive, incluindo as chaves:
|
310
|
+
- `"name"`: Nome do arquivo.
|
311
|
+
- `"id"`: ID do arquivo.
|
312
|
+
- mimeType (str): Tipo do arquivo, por exemplo: xlsx = application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
|
313
|
+
- path (str): diretório onde será salvo o arquivo.
|
314
|
+
|
315
|
+
Retorna:
|
316
|
+
- BytesIO: Objeto em memória contendo os dados do arquivo.
|
317
|
+
- None: Caso ocorra um erro ao tentar abrir ou ler o arquivo.
|
318
|
+
|
319
|
+
Logs:
|
320
|
+
- Registra mensagens indicando o início e o término da leitura do arquivo.
|
321
|
+
- Em caso de falha, registra o erro ocorrido.
|
322
|
+
|
323
|
+
Exceções:
|
324
|
+
- Qualquer erro durante o processo será capturado e registrado no log. A função retornará `None` nesses casos.
|
325
|
+
|
326
|
+
Dependências:
|
327
|
+
- A função assume a existência de um atributo `self.service` configurado para interagir com a API do Google Drive.
|
328
|
+
"""
|
329
|
+
if not os.path.exists(path):
|
330
|
+
os.makedirs(path)
|
331
|
+
try:
|
332
|
+
request = self.service.files().get_media(
|
333
|
+
fileId=file.get("id")
|
334
|
+
)
|
335
|
+
file_path = f"{path}{file["name"]}"
|
336
|
+
with open(file_path, "wb") as f:
|
337
|
+
f.write(request.execute())
|
338
|
+
return {
|
339
|
+
"success": True,
|
340
|
+
"result": file_path,
|
293
341
|
}
|
294
342
|
|
295
343
|
except Exception as e:
|
@@ -3,7 +3,7 @@ csc_cia_stne/bc_correios.py,sha256=pQAnRrcXEMrx3N1MWydZVIhEQLerh3x8-0B045zZIzk,2
|
|
3
3
|
csc_cia_stne/bc_sta.py,sha256=KWHTytM3msAFayt8y5_97RwWHE8Dv8ssfwyh6zU7xI0,25836
|
4
4
|
csc_cia_stne/email.py,sha256=RK_TzWBVnUfpP-s5NvjTJJjzhICy8e2fME9EuaiySMY,8162
|
5
5
|
csc_cia_stne/gcp_bigquery.py,sha256=jYxvqrWDOPkxc05U4aef7V5lL8ptqsE93lfn0dLFyvc,7385
|
6
|
-
csc_cia_stne/google_drive.py,sha256=
|
6
|
+
csc_cia_stne/google_drive.py,sha256=OeBIliKZUxSBcOQwBfAdaQMKChWVWaEudMUDuc1rjU4,14399
|
7
7
|
csc_cia_stne/karavela.py,sha256=jJCYX43D49gGuzmwwK6bN9XVnv2dXdp9iHnnV5H1LMQ,4794
|
8
8
|
csc_cia_stne/logger_json.py,sha256=CXxSCOFGMymDi8XE9SKnPKjW4D0wJLqDLnxqePS26i8,3187
|
9
9
|
csc_cia_stne/logger_rich.py,sha256=WlMqxH1lMy-tzK0I4NpBRgSzPdHc2-YSU71N3SsKM5A,8338
|
@@ -26,8 +26,8 @@ csc_cia_stne/utilitarios/validations/GoogleDriveValidator.py,sha256=PBo-AV2bjR__
|
|
26
26
|
csc_cia_stne/utilitarios/validations/ServiceNowValidator.py,sha256=yleKUIo1ZfyloP9fDPNjv3JJXdLcocT81WIgRSYmqEA,14423
|
27
27
|
csc_cia_stne/utilitarios/validations/__init__.py,sha256=O_qyEU2ji3u6LHUXZCXvUFsMpoMWL625qqHTXyXivTA,106
|
28
28
|
csc_cia_stne/utilitarios/validations/web_validator.py,sha256=HYKYSpDv1RvRjZIuwTPt-AbEz-9392MxM_O329iYuSA,5722
|
29
|
-
csc_cia_stne-0.0.
|
30
|
-
csc_cia_stne-0.0.
|
31
|
-
csc_cia_stne-0.0.
|
32
|
-
csc_cia_stne-0.0.
|
33
|
-
csc_cia_stne-0.0.
|
29
|
+
csc_cia_stne-0.0.69.dist-info/LICENCE,sha256=LPGMtgKki2C3KEZP7hDhA1HBrlq5JCHkIeStUCLEMx4,1073
|
30
|
+
csc_cia_stne-0.0.69.dist-info/METADATA,sha256=HFuGB3cNOVMxx1_KC1uwY1GPJ-94OunEZSoobehMqjI,1340
|
31
|
+
csc_cia_stne-0.0.69.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
32
|
+
csc_cia_stne-0.0.69.dist-info/top_level.txt,sha256=ldo7GVv3tQx5KJvwBzdZzzQmjPys2NDVVn1rv0BOF2Q,13
|
33
|
+
csc_cia_stne-0.0.69.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|