def fetch_files(data, filepath_dict):
'''
Fetch the files given by urls in data['style'] and data['content']
and save them to the corresponding file paths given in filepath_dict.
'''
logger.info('Fetching remote files')
for key, filepath in filepath_dict.items():
if key != settings.OUTPUT_SUFFIX:
file_url = data[key]
logger.info('Fetching remote {} file: {}'.format(key, file_url))
response = requests.get(file_url, stream=True)
if response.status_code == 200:
with open(filepath, 'wb') as outfile:
response.raw.decode_content = True
shutil.copyfileobj(response.raw, outfile)
else:
raise FileNotFoundError('Received 404 when fetching {}'.format(file_url))
评论列表
文章目录