dir handling
parent
3f527bac8c
commit
6d9bb7be3f
Binary file not shown.
After Width: | Height: | Size: 193 KiB |
Binary file not shown.
After Width: | Height: | Size: 201 KiB |
Binary file not shown.
After Width: | Height: | Size: 175 KiB |
Binary file not shown.
After Width: | Height: | Size: 256 KiB |
16
main.py
16
main.py
|
@ -13,6 +13,13 @@ output_path = base_path + '/outputs/'
|
||||||
with open('./template.lbrn', 'r') as file:
|
with open('./template.lbrn', 'r') as file:
|
||||||
template = file.read()
|
template = file.read()
|
||||||
|
|
||||||
|
# create input folder if not exists
|
||||||
|
|
||||||
|
if not os.path.exists(input_path):
|
||||||
|
os.makedirs(input_path)
|
||||||
|
print("Created inputs folder. Insert images in this folder and run the script again.")
|
||||||
|
exit()
|
||||||
|
|
||||||
# read input files
|
# read input files
|
||||||
|
|
||||||
input_files = os.listdir(input_path)
|
input_files = os.listdir(input_path)
|
||||||
|
@ -23,6 +30,9 @@ if len(input_files) == 0:
|
||||||
|
|
||||||
# delete files in output folder
|
# delete files in output folder
|
||||||
|
|
||||||
|
if not os.path.exists(output_path):
|
||||||
|
os.makedirs(output_path)
|
||||||
|
|
||||||
output_files = os.listdir(output_path)
|
output_files = os.listdir(output_path)
|
||||||
|
|
||||||
for output_file_name in output_files:
|
for output_file_name in output_files:
|
||||||
|
@ -43,15 +53,9 @@ for input_file_name in input_files:
|
||||||
t = template.replace('%image%', base64.b64encode(file_content).decode('utf-8'))
|
t = template.replace('%image%', base64.b64encode(file_content).decode('utf-8'))
|
||||||
t = t.replace('%imagePath%', file_path)
|
t = t.replace('%imagePath%', file_path)
|
||||||
|
|
||||||
# write output file
|
|
||||||
output_path = base_path + '/outputs/'
|
|
||||||
|
|
||||||
# remove file extension and add .lbrn
|
# remove file extension and add .lbrn
|
||||||
output_file_name = os.path.splitext(input_file_name)[0] + '.lbrn'
|
output_file_name = os.path.splitext(input_file_name)[0] + '.lbrn'
|
||||||
|
|
||||||
if not os.path.exists(output_path):
|
|
||||||
os.makedirs(output_path)
|
|
||||||
|
|
||||||
output_file_path = os.path.join(output_path, output_file_name)
|
output_file_path = os.path.join(output_path, output_file_name)
|
||||||
|
|
||||||
with open(output_file_path, 'w') as file:
|
with open(output_file_path, 'w') as file:
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue