Skip to content

Commit

Permalink
add conditional check for existing folders
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-samson committed Dec 28, 2023
1 parent 6a84308 commit 080bdf1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
11 changes: 4 additions & 7 deletions combineImages.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ def process_image(primary_filename, primary_folder, secondary_folder, output_fol
secondary_path = os.path.join(secondary_folder, secondary_filename)

# Load primary and secondary images and ignore if image cant be opened
try:
primary_image = Image.open(primary_path)
secondary_image = Image.open(secondary_path)
except:
print(f"Could not open image: {primary_path}, skipping...")
return

primary_image = Image.open(primary_path)
secondary_image = Image.open(secondary_path)
source = Image.open(os.path.join(os.getcwd(), OUTLINE_PATH))

primary_image = primary_image.convert("RGBA")
Expand Down Expand Up @@ -93,7 +90,7 @@ def overlay_images(primary_folder, secondary_folder, output_folder):
primary_filenames = os.listdir(primary_folder)

# Use multiprocessing to process images in parallel
pool = Pool(processes=multiprocessing.cpu_count() - 2)
pool = Pool(processes=5)
pool.starmap(
process_image,
[
Expand Down
10 changes: 8 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,14 @@ def recap():
start_date_range = "2023-01-01"
end_date_range = "2023-12-31"
tokenObj = request.form["tokenObj"]
print("> downloading images locally")
result = get_memories(tokenObj, start_date_range, end_date_range)

# check if a folder called 'primary' exists and 'secondary' exists

result = " "
if not os.path.exists("primary") or not os.path.exists("secondary"):
print("> downloading images locally")
result = get_memories(tokenObj, start_date_range, end_date_range)

if result != "n/a":
# Execute the Python functions
create_images() # process images and apply effects
Expand Down

0 comments on commit 080bdf1

Please sign in to comment.