Merge branch 'master' into develop

pull/6/head
Julius 6 years ago
commit 7da657763e

@ -1,4 +1,3 @@
yaml PyYaml
praw praw
optparse
zipfile zipfile

@ -169,6 +169,22 @@ def download_images(images: list, dl_dir: str):
(realcount, imgcount, dl_dir, preexist)) (realcount, imgcount, dl_dir, preexist))
def filter_zip_files(images: list, zip_fname: str):
"""
Removes the images that already exist in the zip-file
:param images:
:param zip_fname:
:return:
"""
if os.path.isfile(zip_fname):
zfile = zipfile.ZipFile(zip_fname, 'r')
zfnames = [f.filename for f in zfile.infolist()]
print('[~] Removing entries already in zip-file')
return [img for img in images if img.split('/')[-1] not in zfnames]
else:
return images
def compress_folder(folder: str, zip_fname: str): def compress_folder(folder: str, zip_fname: str):
""" """
Zips the contents of a folder to the destination zipfile name. Zips the contents of a folder to the destination zipfile name.
@ -221,9 +237,10 @@ def main():
dldest = options.output # uses the -o output destination dldest = options.output # uses the -o output destination
images = get_images(client, subreddit, limit=options.count, images = get_images(client, subreddit, limit=options.count,
nsfw=options.nsfw) nsfw=options.nsfw)
if options.zip: # download to zip instead if options.zip: # downloads to a cache-folder first before compressing it to zip
download_images(images, '.cache') # download to cache images = filter_zip_files(images, dldest+'.zip')
compress_folder('.cache', dldest + '.zip') # add to zip download_images(images, '.cache')
compress_folder('.cache', dldest+'.zip')
shutil.rmtree('.cache') shutil.rmtree('.cache')
else: else:
download_images(images, dldest) download_images(images, dldest)

Binary file not shown.
Loading…
Cancel
Save