File size: 2,035 Bytes
dbe3173
c2cc76d
0aa95a2
 
 
c2cc76d
6f57a6d
 
39f564f
 
5db1908
 
6f57a6d
5db1908
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39f564f
 
 
5db1908
39f564f
 
 
 
6f57a6d
5db1908
39f564f
5db1908
39f564f
5db1908
 
39f564f
 
5db1908
 
 
 
 
 
 
 
39f564f
5db1908
 
 
 
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
60
61
62
63
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# ファイルからshortcodeを生成する
# Generate shortcode from files

import os
import json
import sys
import argparse
from utils.file_processor import FileProcessor, ProcessorOptions
from pathlib import Path

class JsonShortcodeProcessor(FileProcessor):
    def __init__(self, options: ProcessorOptions, base_dir: Path, url_base: str):
        super().__init__(options)
        self.base_dir = base_dir
        self.url_base = url_base
    
    def process_content(self, content: str) -> str:
        try:
            data = json.loads(content)
            # Process JSON content and generate shortcode
            # (Implementation depends on specific shortcode requirements)
            return self.generate_shortcode(data)
        except json.JSONDecodeError as e:
            self.logger.error(f"Failed to parse JSON: {e}")
            return ""
    
    def generate_shortcode(self, data: dict) -> str:
        # Implement shortcode generation logic here
        pass

def parse_args():
    parser = argparse.ArgumentParser(description='Generate shortcode from files')
    parser.add_argument('directory', nargs='?', default=Path.cwd(),
                      help='Directory to process (default: current directory)')
    parser.add_argument('--url', '-u', default='',
                      help='Base URL for src attribute (e.g., https://example.com)')
    return parser.parse_args()

def main():
    args = parse_args()
    directory = Path(args.directory)
    
    if not directory.is_dir():
        print(f"Error: Directory '{directory}' does not exist")
        sys.exit(1)
    
    options = ProcessorOptions(
        recursive=True,
        dry_run=False,
        file_extensions={'.json'}
    )
    
    processor = JsonShortcodeProcessor(options, directory, args.url)
    print(f"Processing directory: {directory}")
    print(f"Using URL base: {args.url if args.url else '(none)'}")
    processor.process_directory(directory)

if __name__ == "__main__":
    main()