-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
71 lines (55 loc) · 2.13 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
import json
from io import BytesIO
from azure.identity import DefaultAzureCredential
from azure.storage.filedatalake import DataLakeServiceClient
# Configurações
storage_account_name = "cartolaraw"
file_system_name = "team" # Nome do File System
local_file_path = "README.md"
destination_path = "adasda/teste.md"
# Autenticação usando DefaultAzureCredential
credential = DefaultAzureCredential()
# Cria o cliente para o Data Lake Service
service_client = DataLakeServiceClient(
account_url=f"https://{storage_account_name}.dfs.core.windows.net",
credential=credential,
)
# data = "Este é o conteúdo que quero fazer upload."
data = {
"nome": "João",
"idade": 30,
"cidade": "São Paulo"
}
# Converte o objeto para JSON
data_bytes = json.dumps(data).encode("utf-8")
# Obtem o cliente do File System (container)
file_system_client = service_client.get_file_system_client(file_system_name)
# Obtem o cliente do arquivo no ADLS
file_client = file_system_client.get_file_client(destination_path)
# Faz upload do arquivo
file_client.upload_data(data_bytes, overwrite=True)
paths_container = file_system_client.get_paths(path=None, recursive=False)
paths = file_system_client.get_paths(path='adasda', recursive=False)
files_only = [path for path in paths if not path.is_directory]
files_container_only = [path for path in paths_container if not path.is_directory]
downloaded_file = file_client.download_file()
file_content = downloaded_file.readall().decode("utf-8")
from cartola_project.storage import factory_storage
import pandas as pd
# Configurações
storage_account_name = "cartolaraw"
file_system_name = "team" # Nome do File System
destination_path = "adasda/teste_azure.json"
destination_path_2 = "adasda/teste_azure.parquet"
data = {
"nome": "João",
"idade": 30,
"cidade": "São Paulo"
}
data_2 = pd.read_parquet('league_info.parquet')
azure_storage = factory_storage.get_storage('Azure')
azure = azure_storage(storage_account_name, file_system_name)
azure.upload(data, destination_path)
azure.upload(data_2, destination_path_2)
file_json = azure.download(destination_path)
file_parquet = azure.download(destination_path_2)