Skip to content

Commit

Permalink
add crud/utils
Browse files Browse the repository at this point in the history
  • Loading branch information
AthulyaMS committed Jan 8, 2024
1 parent 9a3c8a7 commit 06f3e38
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion app/crud/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sqlalchemy.orm import Session
import db_models
from custom_exceptions import UnprocessableException
# from usfm_grammar import USFMParser, Filter
#pylint: disable=R1732,C0303
def normalize_unicode(text, form="NFKC"):
'''to normalize text contents before adding them to DB'''
Expand Down Expand Up @@ -89,7 +90,10 @@ def numbers():
67: {"book_code": "rev", "book_name": "revelation"}
}

BOOK_CODES = [ val['book_code'] for key, val in books.items()]
# BOOK_CODES = [ val['book_code'] for key, val in books.items()]
BOOK_CODES = { val['book_code']:{'book_num':key, "book_name":val['book_name']}
for key, val in books.items()}



def book_code(book_num):
Expand Down Expand Up @@ -250,3 +254,24 @@ def create_decimal_ref_id(db_:Session, bookcode, chapter, verse):
ref_id = (book_id * 100000) + (chapter * 1000) + verse
return ref_id
raise ValueError("book_id, chapter, and verse must not be None.")


# def parse_usfm(usfm_string):
# '''parse an uploaded usfm file using usfm-grammar'''
# try:
# usfm_parser = USFMParser(normalize_unicode(usfm_string))

# usfm_json = usfm_parser.to_usj(include_markers=Filter.BCV+Filter.TEXT)
# except Exception as exce:
# raise TypeException("Errors in input USFM") from exce

# return usfm_json

# def form_usfm(usj_obj):
# '''convert a usfm-grammar format JSON into usfm'''
# try:
# usj_parser = USFMParser(from_usj=usj_obj)
# usfm_string = usj_parser.usfm
# except Exception as exce:
# raise TypeException("Errors in input USJ(USFM JSON)") from exce
# return usfm_string

0 comments on commit 06f3e38

Please sign in to comment.