-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtry_direct.py
More file actions
99 lines (74 loc) · 3.13 KB
/
Copy pathtry_direct.py
File metadata and controls
99 lines (74 loc) · 3.13 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
import dotenv
import os
from pawfs import connector
dotenv.load_dotenv()
conn = connector.SharepointConnector(
tenant_id=os.getenv("AZURE_TENANT_ID"),
client_id=os.getenv("AZURE_CLIENT_ID"),
client_secret=os.getenv("AZURE_CLIENT_SECRET"),
)
# # List all sites
# sites = connector.list_sites()
# print(sites)
# Get drives for a specific site
site_id = os.getenv("SHAREPOINT_SITE_ID")
drives = conn.get_drives(site_id)
print(drives, "\n\n\n")
drive_id = drives.get("value")[0].get("id") if drives else None
if not drive_id:
raise ValueError("No drives found for the specified site.")
# List files in the root folder of a drive
# drive_id = "your-drive-id"
files = conn.list_folder_contents(drive_id).get("value", [])
for file in files:
print(f"File: {file.get('name')}, ID: {file.get('id')}, Size: {file.get('size')} bytes")
print("\n\n\n", "how about passing in the root folder?")
# List folders in the root folder of a drive
folders = conn.list_folder_contents(drive_id, folder_id="root").get("value", [])
for folder in folders:
if folder.get("folder"):
print(f"Folder: {folder.get('name')}, ID: {folder.get('id')}")
else:
print(f"Item: {folder.get('name')} is not a folder.")
# List all files in a specific folder
# import json
# print("\n\n\n", "lets hope it is pretty")
# # print(json.dumps(files, indent=2))
# with open("files.json", "w") as f:
# json.dump(files, f, indent=2)
# ok, now everything is pretty simple.
# we can make the connection. then use the clinet. to list stuff. check the names and ids.
# and keep what we need.
# if a method is not implemented we can directly use the client to access the API. this is nice.
# lets check out the lists.
# get lists
lists = conn.get_lists(site_id)
print("\n\n\n", "Lists in the site:")
for lst in lists.get("value", []):
print(f"List: {lst.get('name')}, ID: {lst.get('id')}")
# List items in a specific list
list_items = conn.get_list_items(site_id, "Teszt_lista")
# Print the data in each list item
print("\n\n\n", "List Items:")
for item in list_items.get("value", []):
fields = item.get("fields", {})
print(f"\n---- Item ID: {item.get('id')}")
for field_name, field_value in fields.items():
print(f" {field_name}: {field_value}")
print("\n\n\n-----------------", "\n now we are getting a full folder.")
# all i need is my site and drive id. which I can not list. hmm.
# epuletenergetika site:
site_id = os.getenv("ADATVAGYON_SITE_ID") # Replace with your actual site ID
drives = conn.get_drives(site_id)
# drive_id = drives.get("value")[0].get("id") if drives else None # "b!RUt2oP_4TkC-_CWvoUNx68fBAJEFtTxEinZJRKEPP-DYmkAGsYbDR70aG3nMatWL"
for dr in drives.get("value", []):
print(f"Drive: {dr.get('name')}, ID: {dr.get('id')}")
# ok, megvan a ddrive id, de még vannak lejjebb folderek.
# List folders in the root folder of a drive
# drill with the same pattern.
contents = conn.list_folder_contents(drive_id, folder_id="root").get("value", [])
for cont in contents:
if cont.get("folder"):
print(f"Folder: {cont.get('name')}, ID: {cont.get('id')}")
else:
print(f"Item: {cont.get('name')} is not a folder.")