Example #1
0
def search(version, query):
    query = html.escape(query)

    url = "https://www.biblegateway.com/quicksearch/?search=" + query + \
          "&version=" + version + "&searchtype=all&limit=50000&interface=print"

    search_results = {}
    length = 0

    resp = requests.get(url)

    if resp is not None:
        soup = BeautifulSoup(resp.text, "html.parser")

        for row in soup.find_all(True, {"class": "row"}):
            result = {}

            for extra in row.find_all(True, {"class": "bible-item-extras"}):
                extra.decompose()

            result["title"] = row.find(True, {"class": "bible-item-title"})
            result["text"] = row.find(True, {"class": "bible-item-text"})

            if result["title"] is not None:
                if result["text"] is not None:
                    result["title"] = result["title"].getText()
                    result["text"] = remove_bible_title_in_search(
                        bibleutils.purify_text(
                            result["text"].get_text()[0:-1]))

                    length += 1
                    search_results["result" + str(length)] = result
    return search_results
Example #2
0
def get_result(query, version, headings, verse_numbers):
    url = "https://www.biblegateway.com/passage/?search=" + query + \
        "&version=" + version + "&interface=print"

    resp = requests.get(url)

    if resp is not None:
        soup = BeautifulSoup(resp.text, "lxml")

        for div in soup.find_all("div", {"class": "result-text-style-normal"}):
            text = ""
            title = ""

            if headings == "disable":
                for heading in div.find_all("h3"):
                    heading.decompose()

                for heading in div.find_all(True, {"class": "inline-h3"}):
                    heading.decompose()
            else:
                for heading in div.find_all("h3"):
                    title += heading.get_text() + " / "

            for inline in div.find_all(True, {"class": "inline-h3"}):
                inline.decompose()

            for footnote in div.find_all(True, {"class": "footnotes"}):
                footnote.decompose()

            if verse_numbers == "disable":
                for num in div.find_all(True,
                                        {"class": ["chapternum", "versenum"]}):
                    num.string = " "
            else:
                # turn all chapter numbers into "1" otherwise the verse numbers look strange
                for num in div.find_all(True, {"class": "chapternum"}):
                    num.string = "<1> "

                for num in div.find_all(True, {"class": "versenum"}):
                    num.string = "<" + num.string[0:-1] + "> "

            for meta in div.find_all(
                    True, {"class": ["crossreference", "footnote"]}):
                meta.decompose()

            for paragraph in div.find_all("p"):
                text += paragraph.get_text()

            verse_object = {
                "passage": div.find(True, {
                    "class": "passage-display-bcv"
                }).string,
                "version": div.find(True, {
                    "class": "passage-display-version"
                }).string,
                "title": title[0:-3],
                "text": bibleutils.purify_text(text)
            }

            return verse_object
Example #3
0
def get_result(query, version, verse_numbers):
    book = query.split("|")[0]
    chapter = query.split("|")[1].split(":")[0]
    starting_verse = query.split("|")[1].split(":")[1]
    ending_verse = starting_verse

    if "-" in starting_verse:
        temp = starting_verse.split("-")

        if len(temp[1]) != 0:
            starting_verse = temp[0]
            ending_verse = temp[1]
        else:
            starting_verse = temp[0]
            ending_verse = "-"

    book = re.sub(r'\s+', '', book)
    book = book_names[book]

    url = f"https://www.bibleserver.com/text/{version}/{book}{chapter}"

    resp = requests.get(url)
    soup = BeautifulSoup(resp.text, "lxml")

    text = ""

    for div in soup.find_all("div", {"class": "chapter"}):
        for heading in div.find_all("h3", {"class": "caption"}):
            heading.decompose()

        if ending_verse == "-":
            ending_verse = div.find_all(
                "span", {"class": "verseNumber"})[-1].get_text()

        for sup in div.find_all("span", {"class": "verseNumber"}):
            if verse_numbers == "enable":
                sup.replace_with("<" + sup.get_text().strip() + "> ")
            else:
                sup.replace_with(" ")

        for d in div.find_all("div", {"class": "verse"}):
            text += d.get_text()

        text = text.split(f"<{int(ending_verse) + 1}>")[0]

        if int(starting_verse) != 1:
            text = f" <{starting_verse}>" + text.split(
                f"<{int(starting_verse)}>")[1]

        if text is None:
            return

        verse_object = {
            "passage": query.replace("|", " "),
            "version": version_names[version],
            "title": "",
            "text": bibleutils.purify_text(text)
        }

        return verse_object
Example #4
0
def get_result(query, version, verse_numbers):
    book = query.split("|")[0]
    chapter = query.split("|")[1].split(":")[0]
    starting_verse = query.split("|")[1].split(":")[1]
    ending_verse = starting_verse

    if "-" in starting_verse:
        temp = starting_verse.split("-")

        if len(temp[1]) != 0:
            starting_verse = temp[0]
            ending_verse = temp[1]
        else:
            starting_verse = temp[0]
            ending_verse = "-"

    url = f"http://biblehub.com/{version.lower()}/{book.lower()}/{chapter}.htm"

    resp = requests.get(url)
    soup = BeautifulSoup(resp.text, "lxml")

    text = None

    for div in soup.find_all("div", {"class": "chap"}):
        for p in div.find_all("p", {"class": "cross"}):
            p.decompose()

        for heading in div.find_all("p", {"class": "hdg"}):
            heading.decompose()

        if ending_verse == "-":
            ending_verse = div.find_all("span",
                                        {"class": "reftext"})[-1].get_text()

        for sup in div.find_all("span", {"class": "reftext"}):
            if verse_numbers == "enable":
                sup.replace_with("<" + sup.get_text() + "> ")
            else:
                sup.replace_with(" ")

        text = div.get_text()

        text = text.split(f"<{int(ending_verse) + 1}>")[0]

        if int(starting_verse) != 1:
            text = f" <{starting_verse}>" + text.split(
                f"<{int(starting_verse)}>")[1]

        if text is None:
            return

        verse_object = {
            "passage": query.replace("|", " "),
            "version": version_names[version],
            "title": "",
            "text": bibleutils.purify_text(text)
        }

        return verse_object
Example #5
0
def get_result(query, version, headings, verse_numbers):
    query = query.replace("|", " ")

    url = "https://bibles.org/v2/passages.js?q[]=" + query + "&version=" + versions[
        version]

    resp = requests.get(url, auth=(config["apis"]["biblesorg"], "X"))

    if resp is not None:
        data = resp.json()
        data = data["response"]["search"]["result"]["passages"]
        text = None

        if len(data) > 0:
            text = data[0]["text"]

        if text is None:
            return

        soup = BeautifulSoup(text, "lxml")

        title = ""
        text = ""

        for heading in soup.find_all("h3"):
            title += heading.get_text() + " / "
            heading.decompose()

        for sup in soup.find_all("sup", {"class": "v"}):
            if verse_numbers == "enable":
                sup.replace_with("<" + sup.get_text() + "> ")
            else:
                sup.replace_with(" ")

        for p in soup.find_all("p", {"class": "p"}):
            text += p.get_text()

        if headings == "disable":
            title = ""

        verse_object = {
            "passage": query,
            "version": version_names[version],
            "title": title[0:-3],
            "text": bibleutils.purify_text(text)
        }

        return verse_object
Example #6
0
async def search(version, query):
    query = html.escape(query)

    url = f"https://www.biblegateway.com/quicksearch/?search={query}" + \
        f"&version={version}&searchtype=all&limit=50000&interface=print"

    search_results = {}
    length = 0

    async with aiohttp.ClientSession() as session:
        async with session.get(url) as resp:
            if resp is not None:
                soup = BeautifulSoup(await resp.text(), "lxml")

                for row in soup.find_all(True, {"class": "row"}):
                    result = {}

                    for extra in row.find_all(True,
                                              {"class": "bible-item-extras"}):
                        extra.decompose()

                    result["title"] = row.find(True,
                                               {"class": "bible-item-title"})
                    result["text"] = row.find(True,
                                              {"class": "bible-item-text"})

                    if result["title"] is not None:
                        if result["text"] is not None:
                            result["title"] = result["title"].getText()
                            result["text"] = remove_bible_title_in_search(
                                bibleutils.purify_text(
                                    result["text"].get_text()[0:-1]))

                            length += 1
                            search_results["result" + str(length)] = result
            return search_results
Example #7
0
async def get_result(query, version, verse_numbers):
    if "|" in query:
        book = query.split("|")[0]
        chapter = query.split("|")[1].split(":")[0]
        starting_verse = query.split("|")[1].split(":")[1]
        ending_verse = starting_verse
    else:
        book = " ".join(query.split(" ")[:-1])
        chapter = query.split(" ")[-1].split(":")[0]
        starting_verse = query.split(" ")[-1].split(":")[1]
        ending_verse = starting_verse

    if "-" in starting_verse:
        temp = starting_verse.split("-")

        if len(temp[1]) != 0:
            starting_verse = temp[0]
            ending_verse = temp[1]
        else:
            starting_verse = temp[0]
            ending_verse = "-"

    url = f"http://biblehub.com/{version.lower()}/{book.lower()}/{chapter}.htm"

    async with aiohttp.ClientSession() as session:
        async with session.get(url) as resp:
            soup = BeautifulSoup(await resp.text(), "lxml")

            for div in soup.find_all("div", {"class": "chap"}):
                for p in div.find_all("p", {"class": "cross"}):
                    p.decompose()

                for heading in div.find_all("p", {"class": "hdg"}):
                    heading.decompose()

                if ending_verse == "-":
                    ending_verse = div.find_all(
                        "span", {"class": "reftext"})[-1].get_text()

                for sup in div.find_all("span", {"class": "reftext"}):
                    if verse_numbers == "enable":
                        sup.replace_with(f"<**{sup.get_text()}**> ")
                    else:
                        sup.replace_with(" ")

                text = div.get_text()

                text = text.split(f"<**{int(ending_verse) + 1}**>")[0]

                if int(starting_verse) != 1:
                    text = f" <**{starting_verse}**>" + text.split(
                        f"<**{int(starting_verse)}**>")[1]

                if text is None:
                    return

                verse_object = {
                    "passage": query.replace("|", " "),
                    "version": version_names[version],
                    "title": "",
                    "text": bibleutils.purify_text(text)
                }

                return verse_object
Example #8
0
async def get_result(query, version, headings, verse_numbers):
    query = query.replace("|", " ")

    url = f"https://www.biblegateway.com/passage/?search={query}&version={version}&interface=print"

    async with aiohttp.ClientSession() as session:
        async with session.get(url) as resp:
            if resp is not None:
                soup = BeautifulSoup(await resp.text(), "lxml")
                soup.prettify(formatter=lambda s: s.replace(u'\xa0', ' '))

                for div in soup.find_all(
                        "div", {"class": "result-text-style-normal"}):
                    text = ""
                    title = ""

                    if headings == "disable":
                        for heading in div.find_all("h3"):
                            heading.decompose()

                        for heading in div.find_all(True,
                                                    {"class": "inline-h3"}):
                            heading.decompose()
                    else:
                        for heading in div.find_all("h3"):
                            title += f"{heading.get_text()} / "

                    for inline in div.find_all(True, {"class": "inline-h3"}):
                        inline.decompose()

                    for footnote in div.find_all(True, {"class": "footnotes"}):
                        footnote.decompose()

                    if verse_numbers == "disable":
                        for num in div.find_all(
                                True, {"class": ["chapternum", "versenum"]
                                       }):  # noqa: E501
                            num.replace_with(" ")
                    else:
                        # turn chapter numbers into "1" otherwise the verse numbers
                        # look strange
                        for num in div.find_all(True, {"class": "chapternum"}):
                            num.replace_with("<**1**> ")

                        for num in div.find_all(True, {"class": "versenum"}):
                            num.replace_with(f"<**{num.text[0:-1]}**> ")

                    for meta in div.find_all(
                            True, {"class": ["crossreference", "footnote"]
                                   }):  # noqa: E501
                        meta.decompose()

                    for paragraph in div.find_all("p"):
                        text += paragraph.get_text()

                    verse_object = {
                        "passage":
                        div.find(True, {
                            "class": "passage-display-bcv"
                        }).string,  # noqa: E501
                        "version":
                        div.find(True, {
                            "class": "passage-display-version"
                        }).string,  # noqa: E501
                        "title":
                        title[0:-3],
                        "text":
                        bibleutils.purify_text(text)
                    }

                    return verse_object
async def get_result(query, version, verse_numbers):
    if "|" in query:
        book = query.split("|")[0]
        chapter = query.split("|")[1].split(":")[0]
        starting_verse = query.split("|")[1].split(":")[1]
        ending_verse = starting_verse
    else:
        book = " ".join(query.split(" ")[:-1])
        chapter = query.split(" ")[-1].split(":")[0]
        starting_verse = query.split(" ")[-1].split(":")[1]
        ending_verse = starting_verse

    if "-" in starting_verse:
        temp = starting_verse.split("-")

        if len(temp[1]) != 0:
            starting_verse = temp[0]
            ending_verse = temp[1]
        else:
            starting_verse = temp[0]
            ending_verse = "-"

    book = re.sub(r'\s+', '', book)
    book = book_names[book]

    url = f"https://www.bibleserver.com/text/{version}/{book}{chapter}"
    # TODO: Fix this, don't forget to readd versions.

    async with aiohttp.ClientSession() as session:
        async with session.get(url) as resp:
            soup = BeautifulSoup(await resp.text(), "lxml")

            print(soup)

            text = ""

            for div in soup.find_all("div", {"class": "chapter"}):
                for heading in div.find_all("h3", {"class": "caption"}):
                    heading.decompose()

                if ending_verse == "-":
                    ending_verse = div.find_all(
                        "span", {"class": "verseNumber"})[-1].get_text()

                for sup in div.find_all("span", {"class": "verseNumber"}):
                    if verse_numbers == "enable":
                        sup.replace_with(f"<**{sup.get_text().strip()}**> ")
                    else:
                        sup.replace_with(" ")

                for d in div.find_all("div", {"class": "verse"}):
                    text += d.get_text()

                text = text.split(f"<**{int(ending_verse) + 1}**>")[0]

                if int(starting_verse) != 1:
                    text = f" <**{starting_verse}**>" + text.split(
                        f"<**{int(starting_verse)}**>")[1]

                if text is None:
                    return

                verse_object = {
                    "passage": query.replace("|", " "),
                    "version": version_names[version],
                    "title": "",
                    "text": bibleutils.purify_text(text)
                }

                return verse_object