From 3f527bac8cab484859be42b4ed481f43b33a8775 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 7 Oct 2023 23:15:30 +0200 Subject: [PATCH] script --- main.py | 62 ++++++++++++++++++++++++++++++++++++ template.lbrn | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 main.py create mode 100644 template.lbrn diff --git a/main.py b/main.py new file mode 100644 index 0000000..eb5a8f1 --- /dev/null +++ b/main.py @@ -0,0 +1,62 @@ +import os +import base64 + +# paths + +base_path = os.path.dirname(os.path.abspath(__file__)) + +input_path = base_path + '/inputs/' +output_path = base_path + '/outputs/' + +# read template file + +with open('./template.lbrn', 'r') as file: + template = file.read() + +# read input files + +input_files = os.listdir(input_path) + +if len(input_files) == 0: + print("No input files found in " + input_path) + exit() + +# delete files in output folder + +output_files = os.listdir(output_path) + +for output_file_name in output_files: + file_path = os.path.join(output_path, output_file_name) + + if os.path.isfile(file_path): + os.remove(file_path) + +# create output files + +for input_file_name in input_files: + file_path = os.path.join(input_path, input_file_name) + + if os.path.isfile(file_path): + with open(file_path, 'rb') as file: + file_content = file.read() + + t = template.replace('%image%', base64.b64encode(file_content).decode('utf-8')) + t = t.replace('%imagePath%', file_path) + + # write output file + output_path = base_path + '/outputs/' + + # remove file extension and add .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) + + with open(output_file_path, 'w') as file: + file.write(t) + + print("Created file: " + output_file_path) + +print("Done!") diff --git a/template.lbrn b/template.lbrn new file mode 100644 index 0000000..1261923 --- /dev/null +++ b/template.lbrn @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 3.25841e-07 -3.25841e-07 1 399.703 257.016 + + + 1 3.25841e-07 -3.25841e-07 1 289.157 257.016 + + + 1 3.25841e-07 -3.25841e-07 1 344.555 154.108 + V-85 -103.09998c0x-85c0y-105.30911c1x1V-81 -107.09998c0x1c1x-83.209137c1y-107.09998V81 -107.09998c0x83.209137c0y-107.09998c1x1V85 -103.09998c0x1c1x85c1y-105.30911V85 89.31266c0x1c1x1 + B0 1L1 2B2 3L3 4 + + + 1 3.25841e-07 -3.25841e-07 1 344.555 154.108 + V85 89.31266c0x85c0y91.353905c1x1V81.433792 93.28907c0x1c1x83.462997c1y93.067703V60.866211 95.532799c0x58.837002c0y95.754166c1x1V57.299999 99.509209c0x1c1x57.299999c1y97.467964V57.299999 106.09998c0x1c1x1 + + + 1 3.25841e-07 -3.25841e-07 1 344.555 154.108 + V57.299999 106.09998c0x1c1x1V56.299999 107.09998c0x1c1x1V-56.299999 107.09998c0x1c1x1V-57.299999 106.09998c0x1c1x1V-57.299999 99.509209c0x-57.299999c0y97.467964c1x1V-60.866211 95.532799c0x1c1x-58.837002c1y95.754166V-81.433792 93.28907c0x-83.462997c0y93.067703c1x1V-85 89.31266c0x1c1x-85c1y91.353905 + L0 1L1 2L2 3L3 4B4 5L5 6B6 7 + + + 1 3.25841e-07 -3.25841e-07 1 344.555 154.108 + V-85 89.31266c0x1c1x1V-85 -103.09998c0x1c1x1 + L0 1 + + + 0.476578 0 0 0.476578 344.555 154.115 + + +