initial commit

This commit is contained in:
Matthieu Bessat 2022-09-28 22:49:59 +02:00
commit 16137dce12
80 changed files with 1757 additions and 0 deletions

4
import_mess/.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
to_import_*
output.*
new_output.*

View file

@ -0,0 +1,42 @@
#!/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()

View file

@ -0,0 +1,387 @@
[
{
"id": 5,
"mime_type": "image/jpeg",
"original_name": "L'autel à l'intérieur.jpg",
"tags": [
"crypte"
]
},
{
"id": 6,
"mime_type": "image/jpeg",
"original_name": "Aubevoye_-_Bethléem_-_la_crypte_en_1896.jpg",
"tags": [
"crypte"
]
},
{
"id": 7,
"mime_type": "image/jpeg",
"original_name": "dalle-crypte-bethleem1.jpg",
"tags": [
"crypte"
]
},
{
"id": 8,
"mime_type": "image/jpeg",
"original_name": "271904954_245896294360669_963697394648238803_n.jpg",
"tags": [
"crypte"
]
},
{
"id": 9,
"mime_type": "image/jpeg",
"original_name": "entree-crypte-bethleem-11.jpg",
"tags": [
"crypte"
]
},
{
"id": 10,
"mime_type": "image/jpeg",
"original_name": "WhatsApp Image 2022-01-14 at 14.03.06.jpeg",
"tags": [
"crypte"
]
},
{
"id": 11,
"mime_type": "image/jpeg",
"original_name": "WhatsApp Image 2022-01-14 at 14.05.16.jpeg",
"tags": [
"crypte"
]
},
{
"id": 12,
"mime_type": "image/jpeg",
"original_name": "Reproduction de la grotte de la nativité.jpg",
"tags": [
"crypte"
]
},
{
"id": 13,
"mime_type": "image/jpeg",
"original_name": "La statue de la Vierge à l'intérieur de la grotte.jpg",
"tags": [
"crypte"
]
},
{
"id": 14,
"mime_type": "image/jpeg",
"original_name": "crypte_carte_postale.jpg",
"tags": [
"crypte"
]
},
{
"id": 15,
"mime_type": "image/jpeg",
"original_name": "etable.jpg",
"tags": [
"crypte"
]
},
{
"id": 16,
"mime_type": "image/jpeg",
"original_name": "Aubevoye_-_Bethléem_-_entrée_de_la_crypte_-_1896.jpg",
"tags": [
"crypte"
]
},
{
"id": 17,
"mime_type": "image/jpeg",
"original_name": "935_001.jpg",
"tags": [
"crypte"
]
},
{
"id": 18,
"mime_type": "image/jpeg",
"original_name": "47FI3.jpg",
"tags": [
"crypte"
]
},
{
"id": 19,
"mime_type": "image/jpeg",
"original_name": "271697526_616947712731542_8311055355049271148_n.jpg",
"tags": [
"crypte"
]
},
{
"id": 20,
"mime_type": "image/jpeg",
"original_name": "629_001.jpg",
"tags": [
"crypte"
]
},
{
"id": 21,
"mime_type": "image/jpeg",
"original_name": "865_001.jpg",
"tags": [
"crypte"
]
},
{
"id": 22,
"mime_type": "image/jpeg",
"original_name": "Bethleem-pot-crypte.jpg",
"tags": [
"crypte"
]
},
{
"id": 23,
"mime_type": "image/jpeg",
"original_name": "Le plafond de la grotte avec ses lampes.jpg",
"tags": [
"crypte"
]
},
{
"id": 24,
"mime_type": "image/jpeg",
"original_name": "entree-crypte-bethleem-2.jpg",
"tags": [
"crypte"
]
},
{
"id": 25,
"mime_type": "image/jpeg",
"original_name": "Une petite statue de la Vierge à l'intérieur de la grotte.jpg",
"tags": [
"crypte"
]
},
{
"id": 26,
"mime_type": "image/jpeg",
"original_name": "WhatsApp Image 2022-01-14 at 14.04.04.jpeg",
"tags": [
"crypte"
]
},
{
"id": 1000,
"mime_type": "image/jpeg",
"original_name": "CP_vieille_eglise_de_Bethleem_monique_poree.jpg",
"tags": [
"facade"
]
},
{
"id": 1001,
"mime_type": "image/jpeg",
"original_name": "IMG_2561.JPG",
"tags": [
"facade"
]
},
{
"id": 1002,
"mime_type": "image/jpeg",
"original_name": "474_001.jpg",
"tags": [
"facade"
]
},
{
"id": 1003,
"mime_type": "image/jpeg",
"original_name": "174_001.jpg",
"tags": [
"facade"
]
},
{
"id": 1004,
"mime_type": "image/jpeg",
"original_name": "SFI290.jpg",
"tags": [
"facade"
]
},
{
"id": 1005,
"mime_type": "image/jpeg",
"original_name": "WhatsApp Image 2022-01-14 at 14.05.16.jpeg",
"tags": [
"facade"
]
},
{
"id": 1006,
"mime_type": "image/jpeg",
"original_name": "47FI2.jpg",
"tags": [
"facade"
]
},
{
"id": 1007,
"mime_type": "image/jpeg",
"original_name": "Bethleem1959.jpg",
"tags": [
"facade"
]
},
{
"id": 1008,
"mime_type": "image/jpeg",
"original_name": "WhatsApp Image 2022-01-14 at 14.02.33.jpeg",
"tags": [
"facade"
]
},
{
"id": 1009,
"mime_type": "image/jpeg",
"original_name": "Extérieur de derrière la Vierge.jpg",
"tags": [
"facade"
]
},
{
"id": 1010,
"mime_type": "image/jpeg",
"original_name": "791_001.jpg",
"tags": [
"facade"
]
},
{
"id": 1011,
"mime_type": "image/jpeg",
"original_name": "Bethleem1950.jpg",
"tags": [
"facade"
]
},
{
"id": 1012,
"mime_type": "image/jpeg",
"original_name": "057_001.jpg",
"tags": [
"facade"
]
},
{
"id": 1013,
"mime_type": "image/jpeg",
"original_name": "294_001.jpg",
"tags": [
"facade"
]
},
{
"id": 1014,
"mime_type": "image/jpeg",
"original_name": "260_001.jpg",
"tags": [
"facade"
]
},
{
"id": 1015,
"mime_type": "image/jpeg",
"original_name": "760_001.jpg",
"tags": [
"facade"
]
},
{
"id": 1016,
"mime_type": "image/jpeg",
"original_name": "SFI289.jpg",
"tags": [
"facade"
]
},
{
"id": 1017,
"mime_type": "image/jpeg",
"original_name": "498_001.jpg",
"tags": [
"facade"
]
},
{
"id": 1018,
"mime_type": "image/jpeg",
"original_name": "bethleemcouleur.jpg",
"tags": [
"facade"
]
},
{
"id": 1019,
"mime_type": "image/jpeg",
"original_name": "642_001.jpg",
"tags": [
"facade"
]
},
{
"id": 1020,
"mime_type": "image/jpeg",
"original_name": "c5c7b7e1072fb95616855f2803341202.jpg",
"tags": [
"facade"
]
},
{
"id": 1021,
"mime_type": "image/jpeg",
"original_name": "741_001.jpg",
"tags": [
"facade"
]
},
{
"id": 1022,
"mime_type": "image/jpeg",
"original_name": "SFI287_Bethleem_sept_1903.jpg",
"tags": [
"facade"
]
},
{
"id": 1023,
"mime_type": "image/jpeg",
"original_name": "378_001.jpg",
"tags": [
"facade"
]
},
{
"id": 1024,
"mime_type": "image/jpeg",
"original_name": "carte-postale-ancienne-27-aubevoye-chapelle-de-bethleem-animation-1912.jpg",
"tags": [
"facade"
]
},
{
"id": 1025,
"mime_type": "image/jpeg",
"original_name": "carte_postale.jpg",
"tags": [
"facade"
]
}
]

44
import_mess/import_1.py Normal file
View file

@ -0,0 +1,44 @@
import os
import json
import sys
import shutil
import magic
import mimetypes
HUGO_IMAGES = '../static/files/images/'
TO_IMPORT = './to_import_interieur_nef/'
INITIAL_TAGS = ['interieur_nef']
current_index = 51
res = os.listdir(TO_IMPORT)
processed_images = []
for original_file_name in res:
print(f'{current_index} loading {original_file_name}')
folder_name = str(current_index).zfill(5)
os.mkdir(HUGO_IMAGES + folder_name)
old_path = TO_IMPORT + original_file_name
mime_type = magic.from_file(old_path, mime=True)
print(f'found mime {mime_type}')
new_ext = list(filter(lambda x: x[1] == mime_type, mimetypes.types_map.items()))[0][0]
new_path = HUGO_IMAGES + folder_name + '/original' + new_ext
shutil.copyfile(old_path, new_path)
processed_images.append({
'id': current_index,
'original_name': original_file_name,
'mime_type': mime_type,
'tags': INITIAL_TAGS
# name, description
})
current_index += 1
of = open('./output.json', 'w')
of.write(json.dumps(processed_images))
of.close()

View file

@ -0,0 +1,102 @@
#!/bin/python3
"""
For a particular category
Will create markdown files and copy the image
"""
import os
import shutil
import magic
import mimetypes
DEFAULT_TAGS = ['crypte']
SOURCE_DIR = './to_import_crypte/'
CONTENT_DIR = '../content/images/'
# get the current index for the outputdir
content_dir_files = os.listdir(CONTENT_DIR)
current_index = 1
if len(content_dir_files) > 0:
current_index = max(sorted([int(r) for r in content_dir_files]))+1
print(f"current index is {current_index}")
processed_images = []
to_import_files = os.listdir(SOURCE_DIR)
for original_file_name in to_import_files:
print(f'> {current_index} loading {original_file_name}')
new_dir_name = str(current_index).zfill(5) + '/'
if os.path.exists(CONTENT_DIR + new_dir_name):
continue
os.mkdir(CONTENT_DIR + new_dir_name)
image_old_path = SOURCE_DIR + original_file_name
mime_type = magic.from_file(image_old_path, mime=True)
print(f' found mime {mime_type}')
new_ext = list(filter(lambda x: x[1] == mime_type, mimetypes.types_map.items()))[0][0]
image_new_path = CONTENT_DIR + new_dir_name + 'original' + new_ext
# processed_images.append({
# 'id': current_index,
# 'original_name': original_file_name,
# 'mime_type': mime_type,
# 'tags': INITIAL_TAGS
# # name, description
# })
# copy the image to the final place
shutil.copy(image_old_path, image_new_path)
img = {
'id': current_index,
'original_name': original_file_name,
'mime_type': mime_type,
'tags': DEFAULT_TAGS
# name, description
}
# create the markdown file along
image_md = open(CONTENT_DIR + new_dir_name + "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()
current_index += 1
# 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)

View file

@ -0,0 +1,16 @@
#!/bin/python3
# reorder Index des images
import os
BASE = '../static/files/images/'
l = os.listdir(BASE)
print(l)
for e in l:
if int(e) >= 1000:
os.rename(BASE + e, BASE + str(27+int(e)-1000))
if e.zfill(5) != e:
os.rename(BASE + e, BASE + e.zfill(5))

View file

@ -0,0 +1,16 @@
#!/bin/python3
import subprocess
import glob
"""
check recursively every directory
for each image, create resize
"""
for f in glob.iglob('../static/files/images/**/*.jpg', recursive=True):
parent_dir = '/'.join(f.split('/')[:-1])
print(parent_dir)
subprocess.call(['convert', f, '-resize', '350x', parent_dir + '/' + 'thumb-250.jpg'])