-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_from_sharepoint.py
47 lines (36 loc) · 1.39 KB
/
get_from_sharepoint.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
import json
from O365 import Account
import os
from zipfile import ZipFile
with open('office365_credentials.json', 'r') as infile:
data = json.load(infile)
client_id = data['client_id']
client_secret = data['client_secret']
tenant_id = data['tenant_id']
acc = Account((client_id, client_secret), auth_flow_type='credentials', tenant_id=tenant_id)
if acc.authenticate():
print('Authenticated!')
storage = acc.storage()
drives = storage.get_drives()
my_drive = storage.get_default_drive()
root_folder = my_drive.get_root_folder()
for item in my_drive.get_root_folder().get_items():
print(item)
for drive in drives:
print(drive)
for item in drive.get_items():
print(item)
annotations_folder = my_drive.get_item_by_path('/MERC Data/Annotated Images/')
if not os.path.isdir('./data-cache/'):
os.mkdir('./data-cache/')
if not os.path.isdir('./data-cache/raw/'):
os.mkdir('./data-cache/raw/')
for item in annotations_folder.get_items(limit=50):
if item.is_file:
print(f'Downloading {item.name}')
item.download(to_path='./data-cache/')
print(f'Extracting {item.name}')
with ZipFile(f'./data-cache/{item.name}', 'r') as zip_ref:
zip_ref.extractall('./data-cache/raw/')
print(f'Done extracting {item.name}')
pass