Files
marcus-web/scripts/new_lunajuice.py
T

90 lines
2.2 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Create a new standalone Luna Juice post (festivals, events, special occasions).
Usage:
python scripts/new_lunajuice.py # Interactive
python scripts/new_lunajuice.py "Beer Festival 2025" # With title
For regular weekly beer calls, use new_beercall.py instead.
This script is for special events that deserve their own post.
"""
import argparse
import re
import sys
from datetime import datetime, timezone
from pathlib import Path
# Paths
SCRIPT_DIR = Path(__file__).parent
PROJECT_ROOT = SCRIPT_DIR.parent
CONTENT_DIR = PROJECT_ROOT / "content" / "posts" / "beercall"
def slugify(title):
"""Convert title to URL-friendly slug."""
slug = title.lower()
slug = re.sub(r"[^a-z0-9\s-]", "", slug)
slug = re.sub(r"[\s_]+", "-", slug)
slug = re.sub(r"-+", "-", slug)
return slug.strip("-")
def create_post(title, summary=""):
"""Create a new Luna Juice post."""
CONTENT_DIR.mkdir(parents=True, exist_ok=True)
slug = slugify(title)
filename = f"{slug}.md"
filepath = CONTENT_DIR / filename
if filepath.exists():
print(f"Post already exists: {filepath.relative_to(PROJECT_ROOT)}")
overwrite = input("Overwrite? (y/N): ").strip().lower()
if overwrite != "y":
return None
now = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
content = f"""+++
title = '{title}'
date = {now}
draft = true
summary = '{summary}'
series = "Luna Juice"
+++
Write about your beer adventure here...
"""
filepath.write_text(content)
return filepath
def main():
parser = argparse.ArgumentParser(description="Create a new Luna Juice event post")
parser.add_argument("title", nargs="?", help="Post title")
args = parser.parse_args()
if args.title:
title = args.title
else:
title = input("Event title: ").strip()
if not title:
print("Title is required")
sys.exit(1)
summary = input("Summary (one line): ").strip()
filepath = create_post(title, summary)
if filepath:
print(f"\nCreated: {filepath.relative_to(PROJECT_ROOT)}")
print("Edit the file to add your content!")
if __name__ == "__main__":
main()