Using folders "Copies" and "Par label", hopefully
This commit is contained in:
+13
-8
@@ -3,6 +3,7 @@ import json
|
||||
import re
|
||||
import sys
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from collections import defaultdict
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
@@ -213,9 +214,9 @@ def create_jpg(identifier, group_index, group, root_dir):
|
||||
from utils import natural_key
|
||||
|
||||
|
||||
def process_identifier(identifier, files_info, root_dir):
|
||||
def process_identifier(identifier, files_info, output_dir):
|
||||
# Clear output directory if it exists
|
||||
target_folder = os.path.join(root_dir, identifier)
|
||||
target_folder = os.path.join(output_dir, identifier)
|
||||
if os.path.exists(target_folder):
|
||||
shutil.rmtree(target_folder)
|
||||
os.makedirs(target_folder, exist_ok=True)
|
||||
@@ -224,27 +225,31 @@ def process_identifier(identifier, files_info, root_dir):
|
||||
file_groups = group_files(files_info)
|
||||
|
||||
for idx, group in enumerate(file_groups):
|
||||
create_jpg(identifier, idx, group, root_dir)
|
||||
create_jpg(identifier, idx, group, output_dir)
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python app.py <Path_to_Dir>")
|
||||
sys.exit(1)
|
||||
|
||||
root_dir = sys.argv[1]
|
||||
root_dir = Path(sys.argv[1])
|
||||
|
||||
copies_dir = root_dir / "Copies"
|
||||
par_label_dir = root_dir / "Par label"
|
||||
|
||||
print("Scanning files...")
|
||||
data = collect_files(root_dir)
|
||||
data = collect_files(copies_dir)
|
||||
|
||||
print(f"Found {len(data)} identifiers. Processing...")
|
||||
|
||||
# Sort identifiers naturally
|
||||
sorted_identifiers = sorted(data.keys(), key=natural_key)
|
||||
|
||||
# Process using 4 threads
|
||||
with ThreadPoolExecutor(max_workers=4) as executor:
|
||||
# Process using 8 threads
|
||||
with ThreadPoolExecutor(max_workers=8) as executor:
|
||||
for identifier in sorted_identifiers:
|
||||
executor.submit(process_identifier, identifier, data[identifier], root_dir)
|
||||
executor.submit(process_identifier, identifier, data[identifier],
|
||||
par_label_dir)
|
||||
|
||||
print("Done.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user