mirror of
https://github.com/kennethreitz/kjvstudy.org.git
synced 2026-06-05 23:00:16 +00:00
d56a2ea243
Fixed 48 verses where narrative introductions (like "Jesus answered them,") were incorrectly marked in red. Only Christ's actual spoken words should be red. Automatically fixed verses including: - John 8:34: "Jesus answered them," → now in black - John 8:19, 8:49, 8:54: "Jesus answered," → now in black - Matthew 11:25, 12:39, 15:3, 15:13, 17:22, 17:26, 21:30, 21:31, 25:12, 26:10 - Mark 12:29, Luke 4:4, John 5:17, 6:70, 7:16, 10:25, 10:32, 10:34, 13:8 - And 29 more verses across Matthew, Mark, Luke, and John Added script: scripts/fix_red_letter_narrative.py - Automatically extracts spoken words from narrative text - Uses regex patterns to identify narrative introductions - 48 verses fixed, 33 remaining for manual review 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
114 lines
4.0 KiB
Python
114 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Merge new commentary into the main verse_commentary.json file.
|
|
Uses a line-by-line approach to handle the large JSON file.
|
|
"""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
import re
|
|
|
|
def merge_commentary():
|
|
"""Merge new commentary into existing file."""
|
|
|
|
# Paths
|
|
main_file = Path(__file__).parent.parent / "kjvstudy_org" / "data" / "verse_commentary.json"
|
|
new_file = Path(__file__).parent.parent / "kjvstudy_org" / "data" / "verse_commentary_new_10.json"
|
|
backup_file = main_file.with_suffix('.json.backup')
|
|
|
|
print(f"Main file: {main_file}")
|
|
print(f"New file: {new_file}")
|
|
print(f"Backup will be: {backup_file}")
|
|
|
|
# Load the new commentary (small file, safe to load fully)
|
|
print("\nLoading new commentary...")
|
|
with open(new_file, 'r', encoding='utf-8') as f:
|
|
new_data = json.load(f)
|
|
|
|
print(f"Loaded {sum(len(verses) for book in new_data.values() for verses in book.values())} new commentaries")
|
|
|
|
# Create backup of original file
|
|
print("\nCreating backup...")
|
|
import shutil
|
|
shutil.copy2(main_file, backup_file)
|
|
print(f"✓ Backup created: {backup_file}")
|
|
|
|
# Now load main file - try with error recovery
|
|
print("\nLoading main commentary file...")
|
|
print("(This may take a moment - file is ~27MB)")
|
|
|
|
try:
|
|
with open(main_file, 'r', encoding='utf-8') as f:
|
|
main_data = json.load(f)
|
|
print("✓ Main file loaded successfully")
|
|
except json.JSONDecodeError as e:
|
|
print(f"✗ JSON decode error at position {e.pos}: {e.msg}")
|
|
print("\nAttempting to fix JSON...")
|
|
|
|
# Read the file and try to fix common issues
|
|
with open(main_file, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
# Try to fix by removing the problematic section and re-parsing
|
|
# This is a last resort - we'll just skip the broken part
|
|
print("Manual intervention required - JSON file has corruption.")
|
|
print("Please fix the JSON file manually or use the standalone file.")
|
|
return False
|
|
|
|
# Merge new data into main data
|
|
print("\nMerging new commentary into main file...")
|
|
merged_count = 0
|
|
|
|
for book, chapters in new_data.items():
|
|
if book not in main_data:
|
|
main_data[book] = {}
|
|
print(f" + Added new book: {book}")
|
|
|
|
for chapter, verses in chapters.items():
|
|
if chapter not in main_data[book]:
|
|
main_data[book][chapter] = {}
|
|
print(f" + Added new chapter: {book} {chapter}")
|
|
|
|
for verse, content in verses.items():
|
|
main_data[book][chapter][verse] = content
|
|
merged_count += 1
|
|
print(f" ✓ Merged {book} {chapter}:{verse}")
|
|
|
|
# Write merged data back
|
|
print(f"\nWriting merged data to {main_file}...")
|
|
with open(main_file, 'w', encoding='utf-8') as f:
|
|
json.dump(main_data, f, ensure_ascii=False, indent=2)
|
|
|
|
print(f"✓ Successfully merged {merged_count} commentaries")
|
|
print(f"✓ New file size: {main_file.stat().st_size:,} bytes")
|
|
|
|
# Verify
|
|
print("\nVerifying merge...")
|
|
with open(main_file, 'r', encoding='utf-8') as f:
|
|
verify_data = json.load(f)
|
|
|
|
all_verified = True
|
|
for book, chapters in new_data.items():
|
|
for chapter, verses in chapters.items():
|
|
for verse in verses.keys():
|
|
if verse in verify_data.get(book, {}).get(chapter, {}):
|
|
print(f" ✓ Verified {book} {chapter}:{verse}")
|
|
else:
|
|
print(f" ✗ FAILED: {book} {chapter}:{verse}")
|
|
all_verified = False
|
|
|
|
if all_verified:
|
|
print("\n" + "="*60)
|
|
print("SUCCESS! All commentaries merged and verified.")
|
|
print("="*60)
|
|
print(f"Backup available at: {backup_file}")
|
|
return True
|
|
else:
|
|
print("\n" + "="*60)
|
|
print("WARNING: Some verses failed verification!")
|
|
print("="*60)
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
merge_commentary()
|