#!/usr/bin/env python3 # Sunday Comics - Publish script # Copyright (c) 2025 Tomasita Cabrera # Licensed under the MIT License - see LICENSE file for details """ Convenience script to rebuild cache and regenerate all static files. Run this after adding or updating comics. """ import sys import os import subprocess # Add parent directory to path so we can import data_loader sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from data_loader import load_comics_from_yaml, clear_cache def run_script(script_name, description): """Run a script and handle errors""" script_dir = os.path.dirname(os.path.abspath(__file__)) script_path = os.path.join(script_dir, script_name) print(f"{description}...") result = subprocess.run( [sys.executable, script_path], capture_output=True, text=True ) if result.returncode == 0: # Print only the summary line (last non-empty line) output_lines = [line for line in result.stdout.strip().split('\n') if line.strip()] if output_lines: print(f" ✓ {output_lines[-1]}") else: print(f" ✗ Failed!") if result.stderr: print(f" Error: {result.stderr}") return False return True def main(): """Rebuild cache and regenerate all static files""" print("=" * 60) print("Publishing Comics") print("=" * 60) print() # Step 1: Rebuild cache print("1. Rebuilding comics cache...") clear_cache() # Load with cache enabled - since we just cleared it, this will reload from YAML # and automatically save the cache comics = load_comics_from_yaml(use_cache=True) if not comics: print(" ✗ No comics found!") sys.exit(1) print(f" ✓ Cached {len(comics)} comics") print() # Step 2: Generate RSS feed success = run_script('generate_rss.py', '2. Generating RSS feed') if not success: sys.exit(1) print() # Step 3: Generate sitemap success = run_script('generate_sitemap.py', '3. Generating sitemap') if not success: sys.exit(1) print() print("=" * 60) print("✓ All static files updated successfully!") print("=" * 60) if __name__ == '__main__': main()