Prevent files from being downloaded over and over again

This commit is contained in:
Klaus-Uwe Mitterer 2015-05-01 21:59:10 +02:00
parent 0db066c9b9
commit b3a609fa88

3
cah.py
View file

@ -5,10 +5,11 @@ __maintainer__ = __author__
__email__ = "info@klaus-uwe.me" __email__ = "info@klaus-uwe.me"
__version__ = "0.1" __version__ = "0.1"
import requests, bs4, PIL.Image, io import requests, bs4, PIL.Image, io, os
def fileDownloader(url): def fileDownloader(url):
filename = url.split('/')[-1] filename = url.split('/')[-1]
if not os.path.isfile(filename):
remote = requests.get(url, stream=True) remote = requests.get(url, stream=True)
with open(filename, 'wb') as outfile: with open(filename, 'wb') as outfile:
for chunk in remote.iter_content(chunk_size=1024): for chunk in remote.iter_content(chunk_size=1024):