Skip to content

Commit

Permalink
OneDrive examples update
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Mar 16, 2024
1 parent 7ad1a0c commit 2e36a9c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
28 changes: 28 additions & 0 deletions examples/onedrive/folders/download.py
@@ -0,0 +1,28 @@
"""
Download the contents of the driveItem (folder facet)
https://learn.microsoft.com/en-us/graph/api/driveitem-get-content?view=graph-rest-1.0
"""

import os
import tempfile

from office365.graph_client import GraphClient
from office365.onedrive.driveitems.driveItem import DriveItem
from tests import test_client_id, test_password, test_tenant, test_username


def print_progress(downloaded_file):
# type: (DriveItem) -> None
print("File {0} has been downloaded..".format(downloaded_file.web_url))


client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
)
folder_item = client.me.drive.root.get_by_path("archive")

zip_path = os.path.join(tempfile.mkdtemp(), "download.zip")
with open(zip_path, "wb") as f:
folder_item.download_folder(f, print_progress).execute_query()
print("Folder has been downloaded to {0}".format(zip_path))
Expand Up @@ -9,9 +9,11 @@

from office365.graph_client import GraphClient
from office365.onedrive.driveitems.driveItem import DriveItem
from tests.graph_case import acquire_token_by_username_password
from tests import test_client_id, test_password, test_tenant, test_username

client = GraphClient(acquire_token_by_username_password)
client = GraphClient.with_username_and_password(
test_tenant, test_client_id, test_username, test_password
)
folder_item = client.me.drive.root.get_by_path("archive").get().execute_query()

with tempfile.TemporaryDirectory() as local_path:
Expand Down

0 comments on commit 2e36a9c

Please sign in to comment.