Skip to content

Commit

Permalink
solving linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AthulyaMS committed Oct 13, 2023
1 parent 393bffe commit 520e649
Showing 1 changed file with 10 additions and 29 deletions.
39 changes: 10 additions & 29 deletions app/routers/filehandling_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,67 +24,48 @@ async def usfm_parse_resource_bible(request: Request,
resource_name: schemas.TableNamePattern = Path(..., examples="hi_IRV_1_bible"),
book_code: schemas.BookCodePattern=Path(..., examples="mat"),
output_format: usfm_grammar.Format = Path(..., examples="usx"),
content_filter_str: str = Query("PARAGRAPHS"), # Use a string parameter
content_filter: usfm_grammar.Filter = Query(usfm_grammar.Filter.SCRIPTURE_PARAGRAPHS),
chapter: int=Query(None, examples=1),
# verse: int=Query(None, examples=1), last_verse: int=Query(None, examples=15),
active: bool=True,
# skip: int=Query(0, ge=0), limit: int=Query(100, ge=0),
user_details = Depends(get_user_or_none),
db_: Session = Depends(get_db)):
'''Selects a bible from servers and converts it to required format using usfm-grammar'''
log.info("In usfm_parse_resource_bible router function")
log.debug('resource_name: %s, format: %s, filter: %s', resource_name,
output_format, content_filter_str)

# Set a default value for content_filter
content_filter = None

if content_filter_str:
# Convert the string to the enum within the function
content_filter = usfm_grammar.Filter[content_filter_str]

output_format,content_filter)
src_response = await content_apis.get_available_bible_book(
request=request,
resource_name=resource_name,
book_code=book_code,
content_type=schema_content.BookContentType.USFM,
active=active,
skip=0, limit=100,
skip=0,limit=100,
user_details=user_details,
db_=db_
)
)
if "error" in src_response:
raise GenericException(src_response['error'])
if len(src_response) == 0:
raise NotAvailableException(f"Book, {book_code}, is not available in {resource_name}")
input_usfm = src_response[0]['USFM']
log.debug("Obtained usfm from resource bible, %s", input_usfm[:50])

# Parse the USFM content and convert it to JSON
usfm_parser = usfm_grammar.USFMParser(input_usfm)
output_content = usfm_parser.to_usj(content_filter)

return output_content

return files_crud.parse_with_usfm_grammar(input_usfm, output_format, content_filter, chapter)

@router.put('/v2/files/usfm/to/{output_format}',
responses={422: {"model": schemas.ErrorResponse}, 500: {"model": schemas.ErrorResponse}},
status_code=200, tags=['File Handling'])
@get_auth_access_check_decorator
async def parse_uploaded_usfm(request:Request,
output_format: usfm_grammar.Format = Path(..., examples="usx"),
content_filter_str: str = Query("PARAGRAPHS"),
content_filter: usfm_grammar.Filter = Query(usfm_grammar.Filter.SCRIPTURE_PARAGRAPHS),
input_usfm: schema_content.UploadedUsfm = Body(...),
chapter: int=Query(None, examples=1),
# verse: int=Query(None, examples=1), last_verse: int=Query(None, examples=15),
user_details=Depends(get_user_or_none)):
'''Allows to upload a USFM file to be converted to another format. uses usfm-grammar'''
log.info("In parse_uploaded_usfm router function")
log.debug("output_format: %s, content_filter: %s", output_format, content_filter_str)

# Set a default value for content_filter
content_filter = None

if content_filter_str:
# Convert the string to the enum within the function
content_filter = usfm_grammar.Filter[content_filter_str]

log.debug("output_format: %s, content_filter: %s", output_format, content_filter)
return files_crud.parse_with_usfm_grammar(
input_usfm.USFM, output_format, content_filter, chapter)

0 comments on commit 520e649

Please sign in to comment.