mirror of
https://github.com/kennethreitz/kjvstudy.org.git
synced 2026-06-05 06:46:13 +00:00
Restructure project into kjvstudy package
- Move kjv.py and server files into kjvstudy package directory - Add package __init__.py with module imports - Move tests to tests/ directory with path configuration - Add .envrc to prevent Python bytecode generation - Update imports to use relative imports within package - Create global bible instance for reuse across modules
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
from . import kjv
|
||||
from . import server
|
||||
+25
-22
@@ -1,8 +1,11 @@
|
||||
import json
|
||||
from pydantic import BaseModel
|
||||
|
||||
import json
|
||||
|
||||
|
||||
class Bible:
|
||||
"""Represents a Bible."""
|
||||
|
||||
def __init__(self, fname=None):
|
||||
self.fname = fname or "verses-1769.json"
|
||||
|
||||
@@ -11,9 +14,7 @@ class Bible:
|
||||
self.verses = json.load(f)
|
||||
|
||||
def __getitem__(self, verse):
|
||||
"""
|
||||
Returns the text of the verse.
|
||||
"""
|
||||
"""Returns the text of the verse."""
|
||||
|
||||
# Check if the verse exists in the dictionary.
|
||||
if verse not in self.verses:
|
||||
@@ -22,24 +23,30 @@ class Bible:
|
||||
return self.verses[verse]
|
||||
|
||||
def iter_verses(self):
|
||||
"""
|
||||
Iterates over the verses in the Bible.
|
||||
"""
|
||||
"""Iterates over the verses in the Bible."""
|
||||
|
||||
for verse in self.verses:
|
||||
verse_ref = VerseReference.from_string(verse)
|
||||
|
||||
# Remove the leading "# " and brackets from the text.
|
||||
# This is a workaround for the JSON format.
|
||||
# The text is stored as a string with leading "# " and brackets.
|
||||
# Example: "# [In the beginning God created the heaven and the earth.]"
|
||||
text = self.verses[verse]
|
||||
text.replace("# ", "")
|
||||
text.replace("[", "")
|
||||
text.replace("]", "")
|
||||
|
||||
yield Verse(
|
||||
book=verse_ref.book,
|
||||
chapter=verse_ref.chapter,
|
||||
verse=verse_ref.verse,
|
||||
text=self.verses[verse],
|
||||
text=text,
|
||||
)
|
||||
|
||||
def iter_books(self):
|
||||
"""
|
||||
Iterates over the books in the Bible.
|
||||
"""
|
||||
"""Iterates over the books in the Bible."""
|
||||
|
||||
yielded = set()
|
||||
|
||||
for verse in self.verses:
|
||||
@@ -50,9 +57,7 @@ class Bible:
|
||||
yield verse_ref.book
|
||||
|
||||
def iter_chapters(self):
|
||||
"""
|
||||
Iterates over the chapters in the Bible.
|
||||
"""
|
||||
"""Iterates over the chapters in the Bible."""
|
||||
|
||||
yielded = set()
|
||||
|
||||
@@ -64,9 +69,7 @@ class Bible:
|
||||
yield verse_ref.book, verse_ref.chapter
|
||||
|
||||
def iter_chapters_by_book(self):
|
||||
"""
|
||||
Iterates over the chapters in the Bible, grouped by book.
|
||||
"""
|
||||
"""Iterates over the chapters in the Bible, grouped by book."""
|
||||
|
||||
yielded = set()
|
||||
|
||||
@@ -78,9 +81,7 @@ class Bible:
|
||||
yield verse_ref.book, verse_ref.chapter
|
||||
|
||||
def iter_verse_references(self):
|
||||
"""
|
||||
Iterates over the verse references in the Bible.
|
||||
"""
|
||||
"""Iterates over the verse references in the Bible."""
|
||||
|
||||
for verse in self.verses:
|
||||
yield VerseReference.from_string(verse)
|
||||
@@ -123,14 +124,16 @@ class VerseReference(BaseModel):
|
||||
return cls(book=book, chapter=int(chapter), verse=int(verse))
|
||||
|
||||
|
||||
# Create an instance of the Bible class.
|
||||
bible = Bible()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
print(VerseReference.from_string("Genesis 1:1"))
|
||||
print(VerseReference.from_string("I Corinthians 1:1"))
|
||||
print(VerseReference.from_string("John 3:16"))
|
||||
|
||||
bible = Bible()
|
||||
|
||||
print(bible["Genesis 1:1"])
|
||||
# print()
|
||||
# print(verse)
|
||||
@@ -2,7 +2,9 @@ from fastapi import FastAPI, HTTPException, Request
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.templating import Jinja2Templates
|
||||
import kjv # assuming your kjv module is available and contains the Bible class
|
||||
|
||||
from .kjv import bible
|
||||
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@@ -10,8 +12,6 @@ app = FastAPI()
|
||||
app.mount("/static", StaticFiles(directory="static"), name="static")
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
|
||||
bible = kjv.Bible()
|
||||
|
||||
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
def read_root(request: Request):
|
||||
@@ -1,6 +1,11 @@
|
||||
def test_verse_references():
|
||||
from kjv import VerseReference
|
||||
# PATH HACK
|
||||
import os
|
||||
import sys
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from kjvstudy.kjv import VerseReference
|
||||
|
||||
def test_verse_references():
|
||||
# Test the parsing of a verse reference string
|
||||
assert VerseReference.from_string("Genesis 1:1") == VerseReference(
|
||||
book="Genesis", chapter=1, verse=1
|
||||
Reference in New Issue
Block a user