async def mushaf(self, ctx, ref: str, tajweed: str = 'none'): try: surah, ayah = ref.split(':') except ValueError: return await ctx.send(invalid_format) async with self.session.get( f'https://api.alquran.cloud/ayah/{surah}:{ayah}') 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 tajweed is 'none': url = f'https://www.searchtruth.org/quran/images2/large/page-{formatted_page}.jpeg' else: url = f'https://www.searchtruth.org/quran/images1/{formatted_page}.jpg' 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=f'Mushaf / مصحف', icon_url=icon) em.set_image(url=url) await ctx.send(embed=em)
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(separator=" ").strip() text = text.replace(']]', '*]')\ .replace('[[', '[*')\ .replace('*', '')\ .replace('"ayah":', '') \ .replace('"', '') \ .replace('}', ' ﴾') \ .replace('{', ' ﴿') \ .replace(' ).', ').#') \ # 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] text = '***' + text + '***' 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
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') 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