File size: 2,052 Bytes
dbe3173
c2cc76d
 
6f57a6d
 
 
 
516099b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22ae128
 
 
 
 
6f57a6d
516099b
 
 
 
 
 
 
 
 
 
6f57a6d
 
 
 
 
 
 
 
22ae128
6f57a6d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/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)