#!/usr/bin/env python3 """ Script to add a new comic entry to comics_data.py with reasonable defaults """ import sys import os import argparse from datetime import datetime # Add parent directory to path so we can import comics_data sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from comics_data import COMICS def create_markdown_file(date_str, parent_dir): """Create a markdown file for author notes""" author_notes_dir = os.path.join(parent_dir, 'content', 'author_notes') # Create directory if it doesn't exist os.makedirs(author_notes_dir, exist_ok=True) markdown_file = os.path.join(author_notes_dir, f'{date_str}.md') # Check if file already exists if os.path.exists(markdown_file): print(f"Warning: Markdown file already exists: {markdown_file}") return markdown_file # Create file with template content template = f"""# Author Note Write your author note here using markdown formatting. **Example formatting:** - *Italic text* - **Bold text** - [Links](https://example.com) - `Code snippets` """ with open(markdown_file, 'w') as f: f.write(template) print(f"Created markdown file: {markdown_file}") return markdown_file def main(): """Add a new comic entry with defaults""" parser = argparse.ArgumentParser(description='Add a new comic entry to comics_data.py') parser.add_argument('-m', '--markdown', action='store_true', help='Generate a markdown file for author notes') args = parser.parse_args() # Get next number number = max(comic['number'] for comic in COMICS) + 1 if COMICS else 1 # Create entry with defaults comic = { 'number': number, 'filename': f'comic-{number:03d}.png', 'date': datetime.now().strftime('%Y-%m-%d'), 'alt_text': f'Comic #{number}', } # Get path to comics_data.py script_dir = os.path.dirname(os.path.abspath(__file__)) parent_dir = os.path.dirname(script_dir) comics_file = os.path.join(parent_dir, 'comics_data.py') # Read file with open(comics_file, 'r') as f: content = f.read() # Format new entry entry_str = f""" {{ 'number': {comic['number']}, 'filename': {repr(comic['filename'])}, 'date': {repr(comic['date'])}, 'alt_text': {repr(comic['alt_text'])} }}""" # Insert before closing bracket insert_pos = content.rfind(']') new_content = content[:insert_pos] + entry_str + ",\n" + content[insert_pos:] # Write back with open(comics_file, 'w') as f: f.write(new_content) print(f"Added comic #{number}") # Create markdown file if requested if args.markdown: create_markdown_file(comic['date'], parent_dir) if __name__ == '__main__': main()