mirror of
https://github.com/kennethreitz/kjvstudy.org.git
synced 2026-06-05 23:00:16 +00:00
498b191afa
Move static reference data from Python modules to JSON files in data/ directory: - Bible metadata (testament lists, book abbreviations) → bible_metadata.json - Chapter explanations and popularity scores → chapter_explanations.json, popular_chapters.json - Featured verses for verse of the day → featured_verses.json - Resource slugs for sitemap generation → resource_slugs.json Benefits: easier content updates, better separation of data and code, enables non-developer content management. All 252 tests passing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
"""Book name normalization and categorization utilities."""
|
|
import json
|
|
from pathlib import Path
|
|
from functools import lru_cache
|
|
from typing import Optional
|
|
|
|
# Path to bible metadata JSON file
|
|
_METADATA_PATH = Path(__file__).parent.parent / "data" / "bible_metadata.json"
|
|
|
|
|
|
@lru_cache(maxsize=1)
|
|
def _load_bible_metadata() -> dict:
|
|
"""
|
|
Load bible metadata from JSON file.
|
|
Cached since this data never changes and is accessed frequently.
|
|
"""
|
|
with open(_METADATA_PATH, "r", encoding="utf-8") as f:
|
|
return json.load(f)
|
|
|
|
|
|
# Load data from JSON
|
|
_metadata = _load_bible_metadata()
|
|
OT_BOOKS = _metadata["old_testament_books"]
|
|
NT_BOOKS = _metadata["new_testament_books"]
|
|
BOOK_ABBREVIATIONS = _metadata["book_abbreviations"]
|
|
|
|
|
|
def normalize_book_name(book: str) -> Optional[str]:
|
|
"""
|
|
Normalize book name variations to canonical form.
|
|
Returns the canonical book name if a variation is detected, None otherwise.
|
|
"""
|
|
return BOOK_ABBREVIATIONS.get(book)
|
|
|
|
|
|
def is_old_testament(book: str) -> bool:
|
|
"""Check if a book is in the Old Testament."""
|
|
return book in OT_BOOKS
|
|
|
|
|
|
def is_new_testament(book: str) -> bool:
|
|
"""Check if a book is in the New Testament."""
|
|
return book in NT_BOOKS
|
|
|
|
|
|
def get_testament(book: str) -> str:
|
|
"""Return the testament name for a book."""
|
|
if is_old_testament(book):
|
|
return "Old Testament"
|
|
elif is_new_testament(book):
|
|
return "New Testament"
|
|
return "Unknown"
|