45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
|
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()
|