Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix downloading json files from drive #160

Merged
merged 3 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/sync_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ def download_file(item, local_file):
try:
with item.open(stream=True) as response:
with open(local_file, "wb") as file_out:
copyfileobj(response.raw, file_out)
for chunk in response.iter_content(4 * 1024 * 1024):
file_out.write(chunk)
if response.url and "/packageDownload?" in response.url:
local_file = process_package(local_file=local_file)
item_modified_time = time.mktime(item.date_modified.timetuple())
Expand Down
34 changes: 31 additions & 3 deletions tests/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3283,7 +3283,15 @@
"parentId": "FOLDER::com.apple.CloudDocs::D5AA0425-E84F-4501-AF5D-60F1D92648CF",
"dateModified": "2020-04-27T21:37:36Z",
"dateChanged": "2020-04-27T14:44:29-07:00",
"size": 19876991,
"size": os.path.getsize(
os.path.join(
os.path.dirname(__file__),
"ms.band",
"Alternatives",
"000",
"WindowImage.jpg",
)
),
"etag": "2k::2j",
"extension": "pdf",
"hiddenExtension": True,
Expand All @@ -3299,7 +3307,15 @@
"dateModified": "2020-05-03T00:15:17Z",
"dateChanged": "2020-05-02T17:16:17-07:00",
# 'size': 21644358,
"size": os.path.getsize(__file__),
"size": os.path.getsize(
os.path.join(
os.path.dirname(__file__),
"ms.band",
"Alternatives",
"000",
"WindowImage.jpg",
)
),
"etag": "32::2x",
"extension": "pdf",
"hiddenExtension": True,
Expand Down Expand Up @@ -3789,7 +3805,19 @@ def request(self, method, url, **kwargs):
return ResponseMock(DRIVE_PACKAGE_SPECIAL_CHARS_WORKING)
if "icloud-content.com" in url and method == "GET":
if "Scanned+document+1.pdf" in url or "Document scanne 2.pdf" in url:
return ResponseMock({}, raw=open(__file__, "rb"))
return ResponseMock(
{},
raw=open(
os.path.join(
os.path.dirname(__file__),
"ms.band",
"Alternatives",
"000",
"WindowImage.jpg",
),
"rb",
),
)
if "This is a title.md" in url:
return ResponseMock({}, raw=open("This is a title.md", "rb"))
if "Fotoksiążka-Wzór.xmcf" in url:
Expand Down