From a50eeeaf79b3f6ef15ffed8117e689358b558b50 Mon Sep 17 00:00:00 2001 From: Emilia Date: Thu, 7 Dec 2023 20:38:46 -0500 Subject: [PATCH] Move image-fill.py to different repo --- image-fill.py | 55 --------------------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 image-fill.py diff --git a/image-fill.py b/image-fill.py deleted file mode 100644 index 8568f6e..0000000 --- a/image-fill.py +++ /dev/null @@ -1,55 +0,0 @@ -# This script automatically inserts img elements into -# the html file for the pictures page. - -import glob -from pathlib import Path -import argparse -from fileinput import FileInput -from sys import exit - -parser = argparse.ArgumentParser( - prog="ImgInserter", - description="Fills img elements into the html file for the pictures page" -) - -parser.add_argument("html_file", - help="HTML file to be modified") -parser.add_argument("img_dir", - help="""Directory where images are stored; - must be in the same directory as the HTML file""") - -args = parser.parse_args() - -# Find the path to the HTML file -html_path = glob.glob(args.html_file) -if len(html_path) == 0: - print("HTML file provided cannot be found") - exit(1) -html_path = Path(html_path[0]) # Shadow original html_path, now a Path - -# Find the image directory -image_dir = glob.glob(args.img_dir) -if len(image_dir) == 0: - print("Image directory cannot be found") - exit(1) -image_dir = Path(image_dir[0]) # Shadow original image_dir, now a Path - -# Find all images in the image directory -images = list(image_dir.rglob("*.png")) + \ - list(image_dir.rglob("*.jpg")) + \ - list(image_dir.rglob("*.jpeg")) - -# Generate the img tag for each file -imgs = [] -for i in images: - src = str(i.relative_to(i.parents[1])) - imgs.append(f'') - -with FileInput(html_path, inplace=True) as html: - for line in html: - if "Images go below" in line: # Insert imgs here - print(line, end='') - for img in sorted(imgs): - print(img) - else: - print(line, end='')