website_corr/import_mess/create_markdown.py
2022-09-28 22:49:59 +02:00

42 lines
1 KiB
Python

#!/bin/python3
"""
Will create markdown files for all the images
"""
import json
import pathlib
import os
import shutil
inp_file = open('./images_list.json')
images = json.loads(inp_file.read())
CONTENT_BASE = '../content/images/'
FILES_BASE = '../static/files/images/'
dirs = os.listdir(FILES_BASE)
print(sorted(dirs))
for dir in dirs:
if os.path.exists(CONTENT_BASE + dir):
continue
os.mkdir(CONTENT_BASE + dir)
id = int(dir)
print(id - 1)
img = images[int(dir)-1]
print(img)
shutil.copy(FILES_BASE + dir + '/original.jpg', CONTENT_BASE + dir + '/original.jpg')
image_md = open(CONTENT_BASE + dir + "/index.md", "a")
image_md.write("---\n")
image_md.write("title: Image\n")
image_md.write(f"original_name: {img['original_name']}\n")
image_md.write(f"mime_type: {img['mime_type']}\n")
image_md.write(f"tags: {img['tags']}\n")
image_md.write("---\n")
image_md.write("\n")
# description about the image goes after (like the legend)
image_md.close()