Update 'app.py'

main
poni 5 months ago
parent 0116e49be6
commit 78ca5ae0d7

@ -6,6 +6,9 @@ import markdown
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
# automatico open click
def delete_project(): def delete_project():
cms_file = "cms.json" cms_file = "cms.json"
@ -173,13 +176,19 @@ def prepare_project():
# Compress/resize images # Compress/resize images
# os.makedirs(compressed_dir, exist_ok=True) # 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: 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 # Prompt user to select main picture
print("Available pictures:") print("Available pictures:")
for i, image_file in enumerate(image_files, start=1): for i, image_file in enumerate(image_files, start=1):
if image_file != '.DS_Store':
print("{}. {}".format(i, image_file)) print("{}. {}".format(i, image_file))
print("Enter the number of the main picture (or press Enter to keep current): ") print("Enter the number of the main picture (or press Enter to keep current): ")
main_picture_index = input() main_picture_index = input()
@ -195,7 +204,7 @@ def prepare_project():
# Prompt user to choose if main picture appears in the gallery # Prompt user to choose if main picture appears in the gallery
main_in_gallery = True 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": if main_in_gallery_boolean == "yes" or main_in_gallery_boolean == "Yes":
main_in_gallery = True main_in_gallery = True
else: else:
@ -204,23 +213,29 @@ def prepare_project():
# Prompt user to update captions for images # Prompt user to update captions for images
captions_it = project_data.get("captions_it", {}) captions_it = project_data.get("captions_it", {})
captions_en = project_data.get("captions_en", {}) captions_en = project_data.get("captions_en", {})
# clear the dictionary???
captions_it.clear()
captions_en.clear()
for image_file in image_files: for image_file in image_files:
if image_file != '.DS_Store':
if not main_in_gallery: if not main_in_gallery:
if image_file == main_picture: if image_file == main_picture:
continue continue
print("Current caption for '{}' (Italian): {}".format(image_file, captions_it.get(image_file, "No caption"))) # 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() # new_caption_it = input("Enter new caption for '{}' (Italian) (press Enter to keep current): ".format(image_file)).strip()
if new_caption_it: # if new_caption_it:
captions_it[image_file] = new_caption_it # captions_it[image_file] = new_caption_it
elif image_file not in captions_it: # elif image_file not in captions_it:
captions_it[image_file] = "" captions_it[image_file] = ""
print("Current caption for '{}' (English): {}".format(image_file, captions_en.get(image_file, "No caption"))) # 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() # new_caption_en = input("Enter new caption for '{}' (English) (press Enter to keep current): ".format(image_file)).strip()
if new_caption_en: # if new_caption_en:
captions_en[image_file] = new_caption_en # captions_en[image_file] = new_caption_en
elif image_file not in captions_en: # elif image_file not in captions_en:
captions_en[image_file] = "" captions_en[image_file] = ""
# Prompt user to update video URL # 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 # Get gallery images
# os.makedirs('website/galleria/compressed', exist_ok=True) # os.makedirs('website/galleria/compressed', exist_ok=True)
# Compress/resize images # Compress/resize images
for gallery_pic in gallery_pics: for gallery_pic in gallery_pics:
if not gallery_pic.endswith('compressed'): if not gallery_pic.startswith('compress') and gallery_pic != '.DS_Store':
subprocess.run(["convert", os.path.join('website/galleria', gallery_pic), "-resize", "50%", "-define", "jpeg:extent=512kb", os.path.join('website/galleria/', gallery_pic)]) 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 # Initialize Jinja environment
env = Environment(loader=FileSystemLoader('.')) env = Environment(loader=FileSystemLoader('.'))

Loading…
Cancel
Save