Exemple #1
0
def lookup(book=None, chapter=None, verse=None, return_object=False):
    bible_schema = set_schema(many=True)

    if book and chapter and verse:
        if '-' in verse:
            verse_split = verse.split('-')
            verse1 = verse_split[0]
            verse2 = verse_split[1]
            data = Bible.query.filter(or_(Bible.book_id.like(book), Bible.book_abbr.like(book), Bible.book_name.like(book))).filter_by(chapter_id=chapter).filter(Bible.verse_id >= verse1).filter(Bible.verse_id <= verse2)
        elif ',' in verse:
            verse_range = verse.split(',')
            data = Bible.query.filter(or_(Bible.book_id.like(book), Bible.book_abbr.like(book), Bible.book_name.like(book))).filter_by(chapter_id=chapter).filter(Bible.verse_id.in_(verse_range))
        else:
            data = Bible.query.filter(or_(Bible.book_id.like(book), Bible.book_abbr.like(book), Bible.book_name.like(book))).filter_by(chapter_id=chapter).filter_by(verse_id=verse)
    elif book and chapter:
        data = Bible.query.filter(or_(Bible.book_id.like(book), Bible.book_abbr.like(book), Bible.book_name.like(book))).filter_by(chapter_id=chapter)
    elif book:
        data = Bible.query.filter(or_(Bible.book_id.like(book), Bible.book_abbr.like(book), Bible.book_name.like(book)))

    # results = bible_schema.dump(data)
    if return_object:
        if data:
            return data
        else:
            return None
    else:
        data = data.all()
        results = bible_schema.dump(data)
        if results.data:
            return tools.makeResponse(results=results.data, errors=results.errors, message='Lookup Verse(s)')
        else:
            return tools.makeResponse(results=None, errors=False, message='No verses match your query')
def lookup(book=None,
           chapter=None,
           verse=None,
           section=None,
           return_object=False):
    bible_schema = set_schema(many=True)

    if book and chapter and verse:
        verse_data = [x.strip() for x in verse.split(',')]
        verses = []
        for verse_block in verse_data:
            if '-' in verse_block:
                verse_split = verse_block.split('-')
                verse1 = verse_split[0]
                verse2 = verse_split[1]
                verse_range = range(int(verse1), int(verse2) + 1)
                verses.extend(verse_range)
            else:
                verses.append(int(verse_block))

        data = Bible.query.filter(
            or_(Bible.book_id.like(book), Bible.book_abbr.like(book),
                Bible.book_name.like(book))).filter_by(
                    chapter_id=chapter).filter(Bible.verse_id.in_(verses))
    elif book and chapter:
        data = Bible.query.filter(
            or_(Bible.book_id.like(book), Bible.book_abbr.like(book),
                Bible.book_name.like(book))).filter_by(chapter_id=chapter)
    elif book:
        data = Bible.query.filter(
            or_(Bible.book_id.like(book), Bible.book_abbr.like(book),
                Bible.book_name.like(book)))
    elif section:
        data = Bible.query.filter(or_(Bible.section.like(section)))

    # results = bible_schema.dump(data)
    if return_object:
        if data:
            return data
        else:
            return None
    else:
        data = data.all()
        results = bible_schema.dump(data)
        if results.data:
            return tools.makeResponse(results=results.data,
                                      errors=results.errors,
                                      message='Lookup Verse(s)')
        else:
            return tools.makeResponse(results=None,
                                      errors=False,
                                      message='No verses match your query')
Exemple #3
0
def get_chapters(book=None):
    which_rule = tools.getRouteDetails(mod_bible.name, request, 'rule')
    if book:
        book_data = get_book_details(book, False)
        if book_data['count']:
            book_data['results']['chapters'] = {}
            bible_schema = set_schema(only_columns=('chapter_id', 'chapter_id', 'verse_id'), many=True)
            if which_rule == "get_chapters/<book>/verses":
                data = Bible.query.with_entities(func.count(Bible.verse_id).label('verse_id'), Bible.chapter_id).filter(Bible.book_id==book_data['results']['book_id']).group_by(Bible.chapter_id).all()
                results = bible_schema.dump(data)
                book_data['results']['chapters']['count'] = len(results.data)
                book_data['results']['verses'] = {}
                book_data['results']['verses']['by_chapter'] = results.data

                total_verse_count = 0
                for line in results.data:
                    total_verse_count += int(line['verse_id'])

                book_data['results']['verses']['count'] = total_verse_count
                book_data['message'] += ', with chapter count and details'
            else:
                data = Bible.query.with_entities(Bible.chapter_id).filter(Bible.book_id==book_data['results']['book_id']).group_by(Bible.chapter_id).count()
                book_data['results']['chapters']['count'] = data
                book_data['message'] += ', with chapter count'

        return tools.jsonize(book_data)
    else:
        return tools.makeResponse(results=None, errors=True, message='Incomplete command: ' + which_rule)
def get_books_and_sections(section=None):
    bible_schema = set_schema(only_columns=('book_id', 'book_abbr',
                                            'book_name', 'section'),
                              many=True)
    data = None
    message = 'Books'
    if section:
        if section == 'OT' or section == 'NT':
            data = Bible.query.with_entities(
                Bible.book_id, Bible.book_abbr, Bible.book_name,
                Bible.section).filter_by(section=section).group_by(
                    Bible.book_id).order_by(Bible.book_id).all()
            message += ': ' + section

    if not data:
        data = Bible.query.with_entities(
            Bible.book_id, Bible.book_abbr, Bible.book_name,
            Bible.section).group_by(Bible.book_id).order_by(
                Bible.book_id).all()
        which_rule = tools.getRouteDetails(mod_bible.name, request, 'rule')

        if which_rule == 'get_section/':
            message += ': No section selected, listing all'
        else:
            message += ': All'

    results = bible_schema.dump(data)

    return tools.makeResponse(results=results.data,
                              errors=results.errors,
                              message=message)
def keyword(method=None, text=None, book=None, chapter=None, verse=None, section=None):
    bible_schema = set_schema(many=True)
    if text and method:
        if book and chapter and verse:
            data = lookup(book=book, chapter=chapter, verse=verse, return_object=True)
            subquery = True
        elif book and chapter:
            data = lookup(book=book, chapter=chapter, return_object=True)
            subquery = True
        elif book:
            data = lookup(book=book, return_object=True)
            subquery = True
        elif section:
            data = lookup(section=section, return_object=True)
        else:
            data = Bible.query

        if data:
            if method == 'contains':
                data = data.filter(Bible.verse_text.contains(text))
            elif method == 'startswith':
                data = data.filter(Bible.verse_text.startswith(text))
            elif method == 'endswith':
                data = data.filter(Bible.verse_text.endswith(text))
            elif method == 'exact':
                data = data.filter(or_(Bible.verse_text.like("% " + text + " %")
                , Bible.verse_text.like("% " + text + ".%")
                , Bible.verse_text.like("% " + text + ",%")
                , Bible.verse_text.like("% " + text + ";%")
                , Bible.verse_text.like("% " + text + "!%")
                , Bible.verse_text.like("% " + text + "?%")))
            else:
                return tools.makeResponse(results=None, errors=True, message='Incomplete command')

            data.order_by(Bible.id).all()
            results = bible_schema.dump(data)
            return tools.makeResponse(results=results.data, errors=results.errors, message='Verses')
        else:
            return tools.makeResponse(results=None, errors=true, message='No verses matched your query')
    else:
        return tools.makeResponse(results=None, errors=True, message='No verse search method specified (contains, startswith, endswith)')
Exemple #6
0
def keyword(method=None, text=None, book=None, chapter=None, verse=None):
    bible_schema = set_schema(many=True)
    if text and method:
        if book and chapter and verse:
            data = lookup(book=book, chapter=chapter, verse=verse, return_object=True)
            subquery = True
        elif book and chapter:
            data = lookup(book=book, chapter=chapter, return_object=True)
            subquery = True
        elif book:
            data = lookup(book=book, return_object=True)
            subquery = True
        else:
            data = Bible.query

        if data:
            if method == 'contains':
                data = data.filter(Bible.verse_text.contains(text))
            elif method == 'startswith':
                data = data.filter(Bible.verse_text.startswith(text))
            elif method == 'endswith':
                data = data.filter(Bible.verse_text.endswith(text))
            elif method == 'exact':
                data = data.filter(or_(Bible.verse_text.like("% " + text + " %")
                , Bible.verse_text.like("% " + text + ".%")
                , Bible.verse_text.like("% " + text + ",%")
                , Bible.verse_text.like("% " + text + ";%")
                , Bible.verse_text.like("% " + text + "!%")
                , Bible.verse_text.like("% " + text + "?%")))
            else:
                return tools.makeResponse(results=None, errors=True, message='Incomplete command')

            data.order_by(Bible.id).all()
            results = bible_schema.dump(data)
            return tools.makeResponse(results=results.data, errors=results.errors, message='Verses')
        else:
            return tools.makeResponse(results=None, errors=true, message='No verses matched your query')
    else:
        return tools.makeResponse(results=None, errors=True, message='No verse search method specified (contains, startswith, endswith)')
Exemple #7
0
def get_book_details(string, respond=True):
    only_columns = ('book_id', 'book_abbr', 'book_name', 'section')
    bible_schema = set_schema(only_columns=only_columns, many=False)
    message = 'Book: '
    data = Bible.query.filter(or_(Bible.book_id.like(string), Bible.book_abbr.like(string), Bible.book_name.like(string))).group_by(Bible.book_id).first()
    results = bible_schema.dump(data)

    if results:
        message += results.data['book_name']
        count = 1
    else:
        count = 0

    return tools.makeResponse(results=results.data, errors=results.errors, count=count, message=message,  is_json=respond)
def lookup(book=None, chapter=None, verse=None, section=None, return_object=False):
    bible_schema = set_schema(many=True)

    if book and chapter and verse:
        verse_data = [x.strip() for x in verse.split(',')]
        verses = []
        for verse_block in verse_data:
            if '-' in verse_block:
                verse_split = verse_block.split('-')
                verse1 = verse_split[0]
                verse2 = verse_split[1]
                verse_range = range(int(verse1), int(verse2)+1)
                verses.extend(verse_range)
            else:
                verses.append(int(verse_block))

        data = Bible.query.filter(or_(Bible.book_id.like(book), Bible.book_abbr.like(book), Bible.book_name.like(book))).filter_by(chapter_id=chapter).filter(Bible.verse_id.in_(verses))
    elif book and chapter:
        data = Bible.query.filter(or_(Bible.book_id.like(book), Bible.book_abbr.like(book), Bible.book_name.like(book))).filter_by(chapter_id=chapter)
    elif book:
        data = Bible.query.filter(or_(Bible.book_id.like(book), Bible.book_abbr.like(book), Bible.book_name.like(book)))
    elif section:
        data = Bible.query.filter(or_(Bible.section.like(section)))

    # results = bible_schema.dump(data)
    if return_object:
        if data:
            return data
        else:
            return None
    else:
        data = data.all()
        results = bible_schema.dump(data)
        if results.data:
            return tools.makeResponse(results=results.data, errors=results.errors, message='Lookup Verse(s)')
        else:
            return tools.makeResponse(results=None, errors=False, message='No verses match your query')
Exemple #9
0
def get_books_and_sections(section=None):
    bible_schema = set_schema(only_columns=('book_id', 'book_abbr', 'book_name', 'section'), many=True)
    data = None
    message = 'Books'
    if section:
        if section == 'OT' or section == 'NT':
            data = Bible.query.with_entities(Bible.book_id, Bible.book_abbr, Bible.book_name, Bible.section).filter_by(section=section).group_by(Bible.book_id).order_by(Bible.book_id).all()
            message += ': ' + section

    if not data:
        data = Bible.query.with_entities(Bible.book_id, Bible.book_abbr, Bible.book_name, Bible.section).group_by(Bible.book_id).order_by(Bible.book_id).all()
        which_rule = tools.getRouteDetails(mod_bible.name, request, 'rule')

        if which_rule == 'get_section/':
            message += ': No section selected, listing all'
        else:
            message += ': All'

    results = bible_schema.dump(data)

    return tools.makeResponse(results=results.data, errors=results.errors, message=message)
Exemple #10
0
def version():
    version_data = {'version': constants['version']}
    return tools.makeResponse(results=version_data,
                              errors=False,
                              message='API Version Response')
def version():
    version_data = {
        'version': constants['version']
    }
    return tools.makeResponse(results=version_data, errors=False, message='API Version Response')