Skip to content

Commit 4e949a7

Browse files
authored
Merge pull request #1979 from Drakkar-Software/dev
[Community] add download method
2 parents bad983f + 408b519 commit 4e949a7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

octobot/community/authentication.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ def get(self, url, params=None, allow_cache=False, **kwargs):
130130
else:
131131
return self._session.get(url, params=params, **kwargs)
132132

133+
@authentication.authenticated
134+
def download(self, url, target_file, params=None, **kwargs):
135+
with self._session.get(url, stream=True, params=params, **kwargs) as r:
136+
r.raise_for_status()
137+
with open(target_file, 'wb') as f:
138+
for chunk in r.iter_content(chunk_size=8192):
139+
f.write(chunk)
140+
return target_file
141+
133142
@authentication.authenticated
134143
def post(self, url, data=None, json=None, **kwargs):
135144
return self._session.post(url, data=data, json=json, **kwargs)

0 commit comments

Comments
 (0)