From 78ca5ae0d7d787ea79f598dfc1f5841f1aafa0c2 Mon Sep 17 00:00:00 2001 From: poni Date: Mon, 1 Jul 2024 17:53:04 +0200 Subject: [PATCH] Update 'app.py' --- app.py | 60 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/app.py b/app.py index 115dc1f..4fb2f2b 100644 --- a/app.py +++ b/app.py @@ -6,6 +6,9 @@ import markdown from jinja2 import Environment, FileSystemLoader +# automatico open click + + def delete_project(): cms_file = "cms.json" @@ -173,14 +176,20 @@ def prepare_project(): # Compress/resize images # os.makedirs(compressed_dir, exist_ok=True) - image_files = [f for f in os.listdir(assets_dir) if os.path.isfile(os.path.join(assets_dir, f))] + image_files = [f for f in sorted(os.listdir(assets_dir)) if os.path.isfile(os.path.join(assets_dir, f))] for image_file in image_files: - subprocess.run(["convert", os.path.join(assets_dir, image_file), "-resize", "50%", "-define", "jpeg:extent=512kb", os.path.join(assets_dir, image_file)]) - + if not image_file.startswith('compress') and image_file != '.DS_Store': + # print(image_file) + subprocess.run(["magick", os.path.join(assets_dir, image_file), "-resize", "80%", "-define", "jpeg:extent=512kb", os.path.join(assets_dir, image_file)]) + os.rename(os.path.join(assets_dir, image_file), os.path.join(assets_dir, 'compressed_'+image_file.replace(' ', '_'))) + + image_files = [f for f in sorted(os.listdir(assets_dir)) if os.path.isfile(os.path.join(assets_dir, f))] + # Prompt user to select main picture print("Available pictures:") for i, image_file in enumerate(image_files, start=1): - print("{}. {}".format(i, image_file)) + if image_file != '.DS_Store': + print("{}. {}".format(i, image_file)) print("Enter the number of the main picture (or press Enter to keep current): ") main_picture_index = input() if main_picture_index: @@ -195,7 +204,7 @@ def prepare_project(): # Prompt user to choose if main picture appears in the gallery main_in_gallery = True - main_in_gallery_boolean = input("Do you want the main picture be in the gallery? Yes / No :") + main_in_gallery_boolean = input("Do you want the main picture be in the gallery? Yes / No: ") if main_in_gallery_boolean == "yes" or main_in_gallery_boolean == "Yes": main_in_gallery = True else: @@ -204,23 +213,29 @@ def prepare_project(): # Prompt user to update captions for images captions_it = project_data.get("captions_it", {}) captions_en = project_data.get("captions_en", {}) + + # clear the dictionary??? + captions_it.clear() + captions_en.clear() + for image_file in image_files: - if not main_in_gallery: - if image_file == main_picture: - continue + if image_file != '.DS_Store': + if not main_in_gallery: + if image_file == main_picture: + continue - print("Current caption for '{}' (Italian): {}".format(image_file, captions_it.get(image_file, "No caption"))) - new_caption_it = input("Enter new caption for '{}' (Italian) (press Enter to keep current): ".format(image_file)).strip() - if new_caption_it: - captions_it[image_file] = new_caption_it - elif image_file not in captions_it: + # print("Current caption for '{}' (Italian): {}".format(image_file, captions_it.get(image_file, "No caption"))) + # new_caption_it = input("Enter new caption for '{}' (Italian) (press Enter to keep current): ".format(image_file)).strip() + # if new_caption_it: + # captions_it[image_file] = new_caption_it + # elif image_file not in captions_it: captions_it[image_file] = "" - - print("Current caption for '{}' (English): {}".format(image_file, captions_en.get(image_file, "No caption"))) - new_caption_en = input("Enter new caption for '{}' (English) (press Enter to keep current): ".format(image_file)).strip() - if new_caption_en: - captions_en[image_file] = new_caption_en - elif image_file not in captions_en: + + # print("Current caption for '{}' (English): {}".format(image_file, captions_en.get(image_file, "No caption"))) + # new_caption_en = input("Enter new caption for '{}' (English) (press Enter to keep current): ".format(image_file)).strip() + # if new_caption_en: + # captions_en[image_file] = new_caption_en + # elif image_file not in captions_en: captions_en[image_file] = "" # Prompt user to update video URL @@ -308,15 +323,16 @@ def generate_website(): - gallery_pics = [f for f in os.listdir('website/galleria') if not f.startswith('.')] + gallery_pics = [f for f in sorted(os.listdir('website/galleria')) if not f.startswith('.')] # Get gallery images # os.makedirs('website/galleria/compressed', exist_ok=True) # Compress/resize images for gallery_pic in gallery_pics: - if not gallery_pic.endswith('compressed'): - subprocess.run(["convert", os.path.join('website/galleria', gallery_pic), "-resize", "50%", "-define", "jpeg:extent=512kb", os.path.join('website/galleria/', gallery_pic)]) + if not gallery_pic.startswith('compress') and gallery_pic != '.DS_Store': + subprocess.run(["magick", os.path.join('website/galleria', gallery_pic), "-resize", "80%", "-define", "jpeg:extent=512kb", os.path.join('website/galleria/', gallery_pic)]) + os.rename(os.path.join('website/galleria', gallery_pic), os.path.join('website/galleria', 'compressed_'+gallery_pic.replace(' ', '_'))) # Initialize Jinja environment env = Environment(loader=FileSystemLoader('.'))