コード例 #1
0
    def process_footnotes(self):
        text = self.pages[self.page - 1]
        # Now we process the footnotes for the current page.
        # Firstly, we find all the footnotes in the text and add them to the footer text.
        footnotes = re.findall("\[(.*?)\]", text)
        footer = []
        footnote_number = 1
        for footnote in footnotes:
            text = text.replace(footnote, '')
            footnote_number_arabic = convert_to_arabic_number(
                str(footnote_number))
            footer.append(f'\n({footnote_number_arabic}) {footnote}')
            footnote_number = footnote_number + 1
        footer = ''.join(footer)

        # Now we replace the footnotes in the text with a reference:
        total_footnotes = len(footnotes)
        footnote_number = 1
        for x in range(total_footnotes):
            footnote_number_arabic = convert_to_arabic_number(
                str(footnote_number))
            text = text.replace('[]', f'({footnote_number_arabic})', 1)
            footnote_number = footnote_number + 1

        return text, footer
コード例 #2
0
    def process_text(content, page):

        # Parse the website's source and find the tafsir text.
        soup = BeautifulSoup(content, 'html.parser')
        tag = soup.find('div', attrs={'id': 'preloaded'})
        text = tag.get_text().strip()
        text = text.replace('*', '')\
            .replace('⁕', '') \
            .replace('}', ' ﴾') \
            .replace('{', ' ﴿') \
            .replace('﴾', '﴾"')\
            .replace('﴿', '"﴿') \
            .replace('«', '"«') \
            .replace('»', '»"') \
            .replace('"ayah":', '') \
            .replace(']]', ']') \
            .replace('[[', '[')

        cleanb = re.compile('\([^)]*\)')
        text = re.sub(cleanb, '', text)

        # Paginate the text, set the embed text to the current page and calculate how many pages were made:
        try:
            pages = textwrap.wrap(text, 2034, break_long_words=False)
            text = pages[page - 1]
            num_pages = len(pages)
        except IndexError:
            return

        # Now we process the footnotes for the current page.
        # Firstly, we find all the footnotes in the text and add them to the footer text.
        footnotes = re.findall("\[(.*?)\]", text)
        footer = []
        footnote_number = 1
        for footnote in footnotes:
            text = text.replace(footnote, '')
            footnote_number_arabic = convert_to_arabic_number(
                str(footnote_number))
            footer.append(f'\n({footnote_number_arabic}) {footnote}')
            footnote_number = footnote_number + 1
        footer = ''.join(footer)

        # Now we replace the footnotes in the text with a reference:
        total_footnotes = len(footnotes)
        footnote_number = 1
        for x in range(total_footnotes):
            footnote_number_arabic = convert_to_arabic_number(
                str(footnote_number))
            text = text.replace('[]', f'({footnote_number_arabic})', 1)
            footnote_number = footnote_number + 1

        return text, num_pages, footer
コード例 #3
0
    async def _mushaf(self,
                      ctx,
                      ref,
                      show_tajweed: bool,
                      reveal_order: bool = False):
        reference = QuranReference(ref=ref, reveal_order=reveal_order)
        async with self.session.get(
                f'https://api.alquran.cloud/ayah/{reference.surah}:{reference.ayat_list}'
        ) as resp:
            if resp.status != 200:
                return await ctx.send(INVALID_VERSE)
            data = await resp.json()
            page = data['data']['page']

        formatted_page = str(page).zfill(3)
        if show_tajweed:
            url = f'https://www.searchtruth.org/quran/images1/{formatted_page}.jpg'
        else:
            url = f'https://www.searchtruth.org/quran/images2/large/page-{formatted_page}.jpeg'

        arabic_page_number = convert_to_arabic_number(str(page))
        em = discord.Embed(title=f'Page {page}'
                           f'\n  الصفحة{arabic_page_number}',
                           colour=0x006400)
        em.set_author(name='Mushaf / مصحف', icon_url=ICON)
        em.set_image(url=url)

        await ctx.send(embed=em)
コード例 #4
0
    def make_embed(text, page, tafsir_name, surah, ayah, footer, formatted_url, num_pages):

        ref = convert_to_arabic_number(f'{surah}:{ayah}')
        text = text.replace('#', '\n')
        text = f'```py\n{text}\n```'
        em = discord.Embed(title=ref, colour=0x467f05, description=text)
        if footer != '':
            em.set_footer(text=f'Page {page}/{num_pages} \n____________________________________\n{footer}')
        else:
            em.set_footer(text=f'Page {page}/{num_pages}')
        em.set_author(name=f'{tafsir_name}', url=formatted_url, icon_url=icon)

        return em
コード例 #5
0
    def make_embed(self):
        ref = convert_to_arabic_number(f'{self.surah}:{self.ayah}')
        text, footer = self.process_footnotes()

        text = text.replace('#', '\n')
        text = f'```py\n{text}\n```'

        em = discord.Embed(title=ref, colour=0x467f05, description=text)
        if footer != '':
            em.set_footer(
                text=
                f'Page {self.page}/{len(self.pages)} \n____________________________________\n{footer}'
            )
        else:
            em.set_footer(text=f'Page {self.page}/{len(self.pages)}')
        em.set_author(name=f'{self.name}', url=self.url, icon_url=ICON)
        return em