-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathupload_json.py
More file actions
28 lines (20 loc) · 974 Bytes
/
Copy pathupload_json.py
File metadata and controls
28 lines (20 loc) · 974 Bytes
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
"""
Demonstrates how to upload a JSON file to a SharePoint site
"""
import argparse
from office365.sharepoint.client_context import ClientContext
from tests.settings import client_id, password, site_url, tenant, username
def main():
parser = argparse.ArgumentParser(description="Upload a JSON file to a SharePoint site")
parser.add_argument("--list-title", default="Documents", help="document library title")
parser.add_argument("--path", default="../../data/countries.json", help="path to the local file")
args = parser.parse_args()
ctx = ClientContext(site_url).with_username_and_password(
tenant=tenant, client_id=client_id, username=username, password=password
)
folder = ctx.web.lists.get_by_title(args.list_title).root_folder
with open(args.path, "r") as f:
file = folder.files.upload(f).execute_query()
print(f"File has been uploaded into: {file.server_relative_url}")
if __name__ == "__main__":
main()