summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornavanchauhan <navanchauhan@gmail.com>2023-05-01 00:29:57 -0600
committernavanchauhan <navanchauhan@gmail.com>2023-05-01 00:29:57 -0600
commit2076c7eef2f50696485e7d9393e539749f942392 (patch)
treec18f0b59b277bde11e4a0ebfb9f8835795169f1f
parentad3a7eef4b715f1868405024a7d6227d14b0a5ff (diff)
don't generate image if already generated
-rw-r--r--generate_me.py35
1 files changed, 19 insertions, 16 deletions
diff --git a/generate_me.py b/generate_me.py
index 3bd9178..58a644e 100644
--- a/generate_me.py
+++ b/generate_me.py
@@ -71,23 +71,26 @@ for x in os.walk(src_folder):
_post["image_link"] = "/images/opengraph" + fpath.replace(src_folder,"").replace("md","png")
to_write_path = "./Resources" + _post["image_link"]
- img = ImageText((1200,630), background=(238,238,238))
- img.write_text_box((100, 50), _post_title, box_width=1000, font_filename=image_title_font,
- font_size=65, color=image_title_color, place='center')
- img.line(shape=[(400, 400), (800, 400)],fill=image_line_color)
- img.write_text_box((100, 430), f'Tags: {", ".join(_post["tags"])}', box_width=1000, font_filename=image_text_font,
- font_size=32, color=(0,0,0), place='left')
- img.write_text_box((100, 400), f'Date: {_post["date"]}', box_width=1000, font_filename=image_text_font,
- font_size=32, color=(0,0,0), place='left')
- try:
- img.save(to_write_path)
- except FileNotFoundError as e:
- if not os.path.exists(to_write_path.rsplit("/",1)[0]):
- os.makedirs(to_write_path.rsplit("/",1)[0])
+
+ # Check if image exists
+ if not os.path.exists(to_write_path):
+ img = ImageText((1200,630), background=(238,238,238))
+ img.write_text_box((100, 50), _post_title, box_width=1000, font_filename=image_title_font,
+ font_size=65, color=image_title_color, place='center')
+ img.line(shape=[(400, 400), (800, 400)],fill=image_line_color)
+ img.write_text_box((100, 430), f'Tags: {", ".join(_post["tags"])}', box_width=1000, font_filename=image_text_font,
+ font_size=32, color=(0,0,0), place='left')
+ img.write_text_box((100, 400), f'Date: {_post["date"]}', box_width=1000, font_filename=image_text_font,
+ font_size=32, color=(0,0,0), place='left')
+ try:
img.save(to_write_path)
- else:
- print(e)
- exit(1)
+ except FileNotFoundError as e:
+ if not os.path.exists(to_write_path.rsplit("/",1)[0]):
+ os.makedirs(to_write_path.rsplit("/",1)[0])
+ img.save(to_write_path)
+ else:
+ print(e)
+ exit(1)
_post["image_link"] = base_link[:-1] + _post["image_link"]