Added downloading thumbnails to file

This commit is contained in:
2016-03-09 14:00:59 +01:00
parent 8c34f04bc6
commit bdecff27d4
2 changed files with 39 additions and 0 deletions

View File

@@ -2,6 +2,8 @@ import json
import re
import sys
from datetime import datetime
from contextlib import closing
import requests
try:
from urllib.parse import urlencode
@@ -107,3 +109,12 @@ def remove_none_attributes(attributes):
for k, v in attributes.items() if k is not None and v is not None)
else:
return attributes
def download_to_file(url, filename, chunk_size=10 * 1024):
"""Downloads a file via HTTP(S) directly to the filesystem."""
with closing(requests.get(url, stream=True, verify=True)) as req, \
open(filename, 'wb') as outfile:
for block in req.iter_content(chunk_size=chunk_size):
outfile.write(block)