Created
September 13, 2020 10:14
-
-
Save skarfie123/0e380a4e1ed5da78cf3269d2bb35d1b8 to your computer and use it in GitHub Desktop.
Photoframe Filler: take random images from each album folder to the SD card for a photoframe.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example: python "D:\Users\rahul\Documents\Python Scripts\photoframeFiller.py" "D:\image_source" "E:\" | |
# copy from folders (albums) in image_source to sdcard E for photo frame | |
import os | |
import argparse | |
import random | |
import shutil | |
parser = argparse.ArgumentParser() | |
parser.add_argument("fromDir") | |
parser.add_argument("toDir") | |
args = parser.parse_args() | |
answer = input("fromDir: "+args.fromDir+", toDir: "+args.toDir+", are you sure? Y/N: ") | |
if answer.upper() != "Y": | |
exit() | |
while(True): | |
for (_, dirnames, _) in os.walk(args.fromDir): | |
dirname = random.choice(dirnames) | |
for (dirpath, _, filenames) in os.walk(os.path.join(args.fromDir, dirname)): | |
filename = random.choice(filenames) | |
#print(os.path.join(dirpath, filename)) | |
if(os.path.splitext(filename)[1].lower()==".jpg"): | |
print(os.path.join(args.toDir, dirname+" - "+filename)) | |
shutil.copy2(os.path.join(dirpath, filename), os.path.join(args.toDir, dirname+" - "+filename)) | |
break | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment