-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Or, add an optional dict input of a "short title" dictionary. It would be handy when trying to get the output references into a specific format.
I gave it a quick try, but had a hashable dict error:
import pythonbible as bible
from pythonbible.books import Book
text ='Jeremiah 10:11-12;'
titles = {
Book.JEREMIAH: "Jer", # instead of Jeremiah
}
references = bible.get_references(text)
formatted = bible.format_scripture_references(references, short_titles=titles)
print(formatted)I modified two functions. They way you pass through kwargs is pretty nice! I haven't used that before.
# fomatter.py:
def _get_book_title(book: Book, include_books: bool = True, **kwargs: Any) -> str:
if not include_books:
return ""
version: Version = kwargs.get("version", DEFAULT_VERSION)
full_title: bool = kwargs.get("full_title", False)
version_book_titles: BookTitles = get_book_titles(book, version, **kwargs)
return (
version_book_titles.long_title
if full_title
else version_book_titles.short_title
)
# formatter.py:
@lru_cache()
def get_book_titles(book: Book, version: Version, **kwargs: Any) -> BookTitles:
"""Return the book titles for the given Book and optional Version.
:param book: a book of the Bible
:type book: Book
:param version: a version of the Bible, defaults to American Standard
:type version: Version
:return: the long and short titles of the given book and version
:rtype: BookTitles
:raises MissingBookFileError: if the book file for the given book and version does
not exist
"""
short_titles, long_titles = _get_version_book_titles(version or DEFAULT_VERSION)
if short_titles in kwargs:
short_titles = kwargs.short_titles
if long_titles in kwargs:
long_titles = kwargs.long_titles
short_title = short_titles.get(book, book.title)
long_title = long_titles.get(book, book.title)
return BookTitles(long_title, short_title)but get this error:
version_book_titles: BookTitles = get_book_titles(book, version, **kwargs)
TypeError: unhashable type: 'list'
if you've handled this errror before, I'd appreciate a tip :) Otherwise I'll probably give it a shot again sometime.
Thanks!
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request