Skip to content

Commit

Permalink
removed use of context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
fdemello committed Oct 29, 2021
1 parent 9813e00 commit e46f22c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

0.11.2: 2021-10-29
-----------------
Fixes:
- Removed the use of context manager for requests since it's only available after v2.18.0

0.11.0: 2020-08-19
-----------------
New Features:
Expand Down
12 changes: 9 additions & 3 deletions webexteamsarchiver/webexteamsarchiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,15 @@ def _download_file(self, folder_name: str, url: str, filename: str) -> None:

# https://stackoverflow.com/questions/16694907/how-to-download-
# large-file-in-python-with-requests-py
with requests.get(url, headers=headers, stream=True) as r:
with open(os.path.join(os.getcwd(), self.archive_folder_name, folder_name, f"{filename}"), "wb") as f:
shutil.copyfileobj(r.raw, f)
# Removing as it's not support in all requests versions
# with requests.get(url, headers=headers, stream=True) as r:
# with open(os.path.join(os.getcwd(), self.archive_folder_name, folder_name, f"{filename}"), "wb") as f:
# shutil.copyfileobj(r.raw, f)

r = requests.get(url, headers=headers, stream=True)
with open(os.path.join(os.getcwd(), self.archive_folder_name, folder_name, f"{filename}"), "wb") as f:
for chunk in r.iter_content(chunk_size=1024):
f.write(chunk)

def _compress_folder(self, file_format: str) -> str:
"""Compress `archive_folder_name` folder with the format defined by file_format param"""
Expand Down

0 comments on commit e46f22c

Please sign in to comment.