#!/usr/bin/env python # -*- coding: utf-8 -*- import os import json def process_json_file(json_path, base_dir): try: with open(json_path, 'r') as file: data = json.load(file) # Use the filename from the JSON data filename = data['filename'] width = data['width'] height = data['height'] blurhash = data['blurhash'] caption = data['caption'] # Split filename into name and extension image_filename, image_fileextension = os.path.splitext(filename) image_fileextension = image_fileextension.lstrip('.') # Determine the relative directory directory = os.path.relpath(os.path.dirname(json_path), base_dir) directory = directory.replace('static/', '', 1) # Remove the first occurrence of 'static/' # Create the cringe filename cringe_filename = f"{filename}.cringe" # Create the cringe content cringe_content = f"""{{{{< blurhash src="https://huggingface.co/k4d3/yiff_toolkit6/resolve/main/static/{directory}/{filename}" blurhash="{blurhash}" width="{width}" height="{height}" alt="{caption}" grid="true" >}}}}""" # Write the cringe file output_path = os.path.join(os.path.dirname(json_path), cringe_filename) with open(output_path, 'w') as cringe_file: cringe_file.write(cringe_content) print(f"Processed: {json_path}") except Exception as e: print(f"Error processing {json_path}: {str(e)}") def recurse_directories(base_dir): for root, _, files in os.walk(base_dir): for file in files: if file.endswith('.json'): process_json_file(os.path.join(root, file), base_dir) if __name__ == "__main__": base_directory = os.path.join(os.getcwd(), 'yiff_toolkit6') recurse_directories(base_directory)