From da9c599049c111b4df6ed2616e425776d05ead79 Mon Sep 17 00:00:00 2001 From: yasir Date: Sun, 15 Jan 2023 14:54:52 +0700 Subject: [PATCH] Tes --- misskaty/core/message_utils.py | 17 +++--- misskaty/plugins/web_scraper.py | 100 ++++++++++++++++---------------- 2 files changed, 60 insertions(+), 57 deletions(-) diff --git a/misskaty/core/message_utils.py b/misskaty/core/message_utils.py index e94161c5..c6aa4bd0 100644 --- a/misskaty/core/message_utils.py +++ b/misskaty/core/message_utils.py @@ -8,30 +8,31 @@ LOGGER = getLogger(__name__) # handler for TG function, so need write exception in every code -async def kirimPesan(msg, text: str, disable_web_page_preview=True, reply_markup=None): +# Send MSG Pyro +async def kirimPesan(msg, text: str, quote=True, disable_web_page_preview=True, reply_markup=None): try: - return await msg.reply(text=text, disable_web_page_preview=disable_web_page_preview, reply_markup=reply_markup) + return await msg.reply(text=text, quote=quote, disable_web_page_preview=disable_web_page_preview, reply_markup=reply_markup) except FloodWait as e: LOGGER.warning(str(e)) await asyncio.sleep(e.value) - return await kirimPesan(msg, text=text, disable_web_page_preview=disable_web_page_preview, reply_markup=reply_markup) - except ChatWriteForbidden: - return await msg.leave() + return await kirimPesan(msg, text=text, quote=quote, disable_web_page_preview=disable_web_page_preview, reply_markup=reply_markup) except Exception as e: LOGGER.error(str(e)) + return - +# Edit MSG Pyro async def editPesan(msg, text: str, disable_web_page_preview=True, reply_markup=None): try: - return await msg.edit(text=text, disable_web_page_preview=disable_web_page_preview, reply_markup=reply_markup) + return await msg.edit(text=text, parse_mode=parse_mode, disable_web_page_preview=disable_web_page_preview, reply_markup=reply_markup) except FloodWait as e: LOGGER.warning(str(e)) await asyncio.sleep(e.value) - return await editPesan(msg, text=text, disable_web_page_preview=disable_web_page_preview, reply_markup=reply_markup) + return await editPesan(msg, text=text, parse_mode=parse_mode, disable_web_page_preview=disable_web_page_preview, reply_markup=reply_markup) except MessageNotModified: return except Exception as e: LOGGER.error(str(e)) + return async def hapusPesan(msg): diff --git a/misskaty/plugins/web_scraper.py b/misskaty/plugins/web_scraper.py index ade76996..df5accb4 100644 --- a/misskaty/plugins/web_scraper.py +++ b/misskaty/plugins/web_scraper.py @@ -53,7 +53,7 @@ async def getDataTerbit21(msg, kueri, CurrentPage): else: terbitjson = (await http.get(f'https://yasirapi.eu.org/terbit21?q={kueri}')).json() if not terbitjson.get("result"): - await msg.edit("Sorry, could not find any results!") + await editPesan(msg, "Sorry, could not find any results!") return None, None SCRAP_DICT[msg.id] = [split_arr(terbitjson["result"], 6), kueri] try: @@ -71,7 +71,7 @@ async def getDataTerbit21(msg, kueri, CurrentPage): TerbitRes = ''.join(i for i in TerbitRes if not i in IGNORE_CHAR) return TerbitRes, PageLen except (IndexError, KeyError): - await msg.edit("Sorry, could not find any results!") + await editPesan(msg, "Sorry, could not find any results!") return None, None # LK21 GetData @@ -82,7 +82,7 @@ async def getDatalk21(msg, kueri, CurrentPage): else: lk21json = (await http.get(f'https://yasirapi.eu.org/lk21?q={kueri}')).json() if not lk21json.get("result"): - await msg.edit("Sorry could not find any matching results!") + await editPesan(msg, "Sorry could not find any matching results!") return None, None SCRAP_DICT[msg.id] = [split_arr(lk21json["result"], 6), kueri] try: @@ -100,7 +100,7 @@ async def getDatalk21(msg, kueri, CurrentPage): lkResult = ''.join(i for i in lkResult if not i in IGNORE_CHAR) return lkResult, PageLen except (IndexError, KeyError): - await msg.edit("Sorry could not find any matching results!") + await editPesan(msg, "Sorry could not find any matching results!") return None, None # Pahe GetData @@ -108,7 +108,7 @@ async def getDataPahe(msg, kueri, CurrentPage): if not SCRAP_DICT.get(msg.id): pahejson = (await http.get(f'https://yasirapi.eu.org/pahe?q={kueri}')).json() if not pahejson.get("result"): - await msg.edit("Sorry could not find any matching results!", quote=True) + await editPesan(msg, "Sorry could not find any matching results!") return None, None SCRAP_DICT[msg.id] = [split_arr(pahejson["result"], 6), kueri] try: @@ -122,7 +122,7 @@ async def getDataPahe(msg, kueri, CurrentPage): paheResult = ''.join(i for i in paheResult if not i in IGNORE_CHAR) return paheResult, PageLen except (IndexError, KeyError): - await msg.edit("Sorry could not find any matching results!") + await editPesan(msg, "Sorry could not find any matching results!") return None, None # Nodrakor GetData @@ -133,10 +133,10 @@ async def getDataNodrakor(msg, kueri, CurrentPage): entry = text.find_all(class_="entry-header") if "Nothing Found" in entry[0].text: if not kueri: - await msg.edit("404 Not FOUND!") + await editPesan(msg, "Sorry, could not find any result.") return None, None else: - await msg.edit(f"404 Not FOUND For: {kueri}") + await editPesan(msg, f"Sorry, could not find any result for: {kueri}") return None, None data = [] for i in entry: @@ -158,7 +158,7 @@ async def getDataNodrakor(msg, kueri, CurrentPage): NodrakorResult = ''.join(i for i in NodrakorResult if not i in IGNORE_CHAR) return NodrakorResult, PageLen except (IndexError, KeyError): - await msg.edit("Sorry could not find any matching results!") + await editPesan(msg, "Sorry could not find any matching results!") return None, None # Kusonime GetData @@ -173,7 +173,7 @@ async def getDataKuso(msg, kueri, CurrentPage): link = ress["href"] kusodata.append({"title": title, "link": link}) if not kusodata: - await msg.edit("Sorry could not find any results!") + await editPesan(msg, "Sorry could not find any results!") return None, None SCRAP_DICT[msg.id] = [split_arr(kusodata, 6), kueri] try: @@ -187,7 +187,7 @@ async def getDataKuso(msg, kueri, CurrentPage): kusoResult = ''.join(i for i in kusoResult if not i in IGNORE_CHAR) return kusoResult, PageLen except (IndexError, KeyError): - await msg.edit("Sorry could not find any matching results!") + await editPesan(msg, "Sorry could not find any matching results!") return None, None # Movieku GetData @@ -204,7 +204,7 @@ async def getDataMovieku(msg, kueri, CurrentPage): typee = typ.strip() if typ.strip() != "" else "~" moviekudata.append({"judul": judul, "link": link, "type": typee}) if not moviekudata: - await msg.edit("Sorry could not find any results!") + await editPesan(msg, "Sorry could not find any results!") return None, None SCRAP_DICT[msg.id] = [split_arr(moviekudata, 6), kueri] try: @@ -218,7 +218,7 @@ async def getDataMovieku(msg, kueri, CurrentPage): moviekuResult = ''.join(i for i in moviekuResult if not i in IGNORE_CHAR) return moviekuResult, PageLen except (IndexError, KeyError): - await msg.edit("Sorry could not find any matching results!") + await editPesan(msg, "Sorry could not find any matching results!") return None, None # Savefilm21 GetData @@ -230,34 +230,34 @@ async def getDataSavefilm21(msg, kueri, CurrentPage): entry = text.find_all(class_="entry-header") if "Tidak Ditemukan" in entry[0].text: if not kueri: - await msg.edit("404 Not FOUND!") - return None, None + await editPesan(msg, "Sorry, could not find any result") + return None, 0, None else: - await msg.edit(f"404 Not FOUND For: {kueri}") - return None, None + await editPesan(msg, f"Sorry, could not find any result for: {kueri}") + return None, 0, None for i in entry: genre = i.find(class_="gmr-movie-on").text genre = f"{genre}" if genre != "" else "N/A" judul = i.find(class_="entry-title").find("a").text link = i.find(class_="entry-title").find("a").get("href") sfdata.append({"judul": judul, "link": link, "genre": genre}) - if not sfdata: - await msg.edit("Sorry could not find any results!", quote=True) - return None, None SCRAP_DICT[msg.id] = [split_arr(sfdata, 6), kueri] try: index = int(CurrentPage - 1) PageLen = len(SCRAP_DICT[msg.id][0]) - + extractbtn = [] sfResult = f"#SaveFilm21 Latest:\nšŸŒ€ Use /savefilm21 [title] to start search with title.\n\n" if kueri == "" else f"#Savefilm21 Results For: {kueri}\n\n" for c, i in enumerate(SCRAP_DICT[msg.id][0][index], start=1): sfResult += f"{c}. {i['judul']}\nGenre: {i['genre']}\nExtract: /savefilm21_scrap {i['link']}\n\n" + extractbtn.append( + InlineButton(c, f"sf21extract#{CurrentPage}#{c}#{msg.from_user.id}#{msg.id}") + ) IGNORE_CHAR = "[]" sfResult = ''.join(i for i in sfResult if not i in IGNORE_CHAR) - return sfResult, PageLen + return sfResult, PageLen, extractbtn except (IndexError, KeyError): - await msg.edit("Sorry could not find any matching results!") - return None, None + await editPesan(msg, "Sorry could not find any matching results!") + return None, 0, None # Lendrive GetData async def getDataLendrive(msg, kueri, CurrentPage): @@ -272,7 +272,7 @@ async def getDataLendrive(msg, kueri, CurrentPage): kualitas = o.find(class_="typez TV").text if o.find(class_="typez TV") else o.find(class_="typez BD") lenddata.append({"judul": title, "link": link, "quality": kualitas, "status": status}) if not lenddata: - await msg.edit("Sorry could not find any results!") + await editPesan(msg, "Sorry could not find any results!") return None, None SCRAP_DICT[msg.id] = [split_arr(lenddata, 6), kueri] try: @@ -286,7 +286,7 @@ async def getDataLendrive(msg, kueri, CurrentPage): lenddataResult = ''.join(i for i in lenddataResult if not i in IGNORE_CHAR) return lenddataResult, PageLen except (IndexError, KeyError): - await msg.edit("Sorry could not find any matching results!") + await editPesan(msg, "Sorry could not find any matching results!") return None, None # MelongMovie GetData @@ -305,7 +305,7 @@ async def getDataMelong(msg, kueri, CurrentPage): quality = "N/A" melongdata.append({"judul": title, "link": url, "quality": quality}) if not melongdata: - await msg.edit("Sorry could not find any results!") + await editPesan(msg, "Sorry could not find any results!") return None, None SCRAP_DICT[msg.id] = [split_arr(melongdata, 6), kueri] try: @@ -319,21 +319,21 @@ async def getDataMelong(msg, kueri, CurrentPage): melongResult = ''.join(i for i in melongResult if not i in IGNORE_CHAR) return melongResult, PageLen except (IndexError, KeyError): - await msg.edit("Sorry could not find any matching results!") + await editPesan(msg, "Sorry could not find any matching results!") return None, None # Zonafilm GetData async def getDataZonafilm(msg, kueri, CurrentPage): if not SCRAP_DICT.get(msg.id): - zonafilm = await http.get(f'https://zonafilm.icu/?s={kueri}', headers=headers) + zonafilm = await http.get(f'http://194.195.90.100//?s={kueri}', headers=headers) text = BeautifulSoup(zonafilm.text, "lxml") entry = text.find_all(class_="entry-header") - if "Nothing Found" in entry[0].text: + if entry[0].text.strip() == "Nothing Found": if not kueri: - await msg.edit("Sorry, not found any result!") + await editPesan(msg, "Sorry, not found any result!") return None, None else: - await msg.edit(f"Sorry not found any result for: {kueri}") + await editPesan(msg, f"Sorry not found any result for: {kueri}") return None, None data = [] for i in entry: @@ -355,7 +355,7 @@ async def getDataZonafilm(msg, kueri, CurrentPage): ZonafilmResult = ''.join(i for i in ZonafilmResult if not i in IGNORE_CHAR) return ZonafilmResult, PageLen except (IndexError, KeyError): - await msg.edit("Sorry could not find any matching results!") + await editPesan(msg, "Sorry could not find any matching results!") return None, None # GoMov GetData @@ -364,12 +364,12 @@ async def getDataGomov(msg, kueri, CurrentPage): gomovv = await http.get(f'https://185.173.38.216/?s={kueri}', headers=headers) text = BeautifulSoup(gomovv.text, "lxml") entry = text.find_all(class_="entry-header") - if "Nothing Found" in entry[0].text: + if entry[0].text.strip() == "Nothing Found": if not kueri: - await msg.edit("404 Not FOUND!") + await editPesan(msg, "Sorry, i could not find anything.") return None, None else: - await msg.edit(f"404 Not FOUND For: {kueri}") + await editPesan(msg, f"Sorry, i could not find query: {kueri}") return None, None data = [] for i in entry: @@ -391,7 +391,7 @@ async def getDataGomov(msg, kueri, CurrentPage): gomovResult = ''.join(i for i in gomovResult if not i in IGNORE_CHAR) return gomovResult, PageLen except (IndexError, KeyError): - await msg.edit("Sorry could not find any matching results!") + await editPesan(msg, "Sorry could not find any matching results!") return None, None # Terbit21 CMD @@ -400,7 +400,7 @@ async def terbit21_s(client, message): kueri = ' '.join(message.command[1:]) if not kueri: kueri = None - pesan = await message.reply("ā³ Please wait, scraping data from Terbit21..", quote=True) + pesan = await kirimPesan(message, "ā³ Please wait, scraping data from Terbit21..", quote=True) CurrentPage = 1 terbitres, PageLen = await getDataTerbit21(pesan, kueri, CurrentPage) if not terbitres: return @@ -418,7 +418,7 @@ async def lk21_s(client, message): kueri = ' '.join(message.command[1:]) if not kueri: kueri = None - pesan = await message.reply("ā³ Please wait, scraping data from LK21..", quote=True) + pesan = await kirimPesan(message, "ā³ Please wait, scraping data from LK21..", quote=True) CurrentPage = 1 lkres, PageLen = await getDatalk21(pesan, kueri, CurrentPage) if not lkres: return @@ -436,7 +436,7 @@ async def pahe_s(client, message): kueri = ' '.join(message.command[1:]) if not kueri: kueri = "" - pesan = await message.reply("ā³ Please wait, scraping data from Pahe Web..", quote=True) + pesan = await kirimPesan(message, "ā³ Please wait, scraping data from Pahe Web..", quote=True) CurrentPage = 1 paheres, PageLen = await getDataPahe(pesan, kueri, CurrentPage) if not paheres: return @@ -453,7 +453,7 @@ async def gomov_s(client, message): kueri = ' '.join(message.command[1:]) if not kueri: kueri = "" - pesan = await message.reply("ā³ Please wait, scraping data Gomov Web..", quote=True) + pesan = await kirimPesan(message, "ā³ Please wait, scraping data Gomov Web..", quote=True) CurrentPage = 1 gomovres, PageLen = await getDataGomov(pesan, kueri, CurrentPage) if not gomovres: return @@ -470,7 +470,7 @@ async def zonafilm_s(client, message): kueri = ' '.join(message.command[1:]) if not kueri: kueri = "" - pesan = await message.reply("ā³ Please wait, scraping data from Zonafilm Web..", quote=True) + pesan = await kirimPesan(message, "ā³ Please wait, scraping data from Zonafilm Web..", quote=True) CurrentPage = 1 zonafilmres, PageLen = await getDataZonafilm(pesan, kueri, CurrentPage) if not zonafilmres: return @@ -487,7 +487,7 @@ async def melong_s(client, message): kueri = ' '.join(message.command[1:]) if not kueri: kueri = "" - pesan = await message.reply("ā³ Please wait, scraping data from Melongmovie..", quote=True) + pesan = await kirimPesan(message, "ā³ Please wait, scraping data from Melongmovie..", quote=True) CurrentPage = 1 melongres, PageLen = await getDataMelong(pesan, kueri, CurrentPage) if not melongres: return @@ -504,12 +504,14 @@ async def savefilm_s(client, message): kueri = ' '.join(message.command[1:]) if not kueri: kueri = "" - pesan = await message.reply("ā³ Please wait, scraping data from Savefilm21..", quote=True) + pesan = await kirimPesan(message, "ā³ Please wait, scraping data from Savefilm21..", quote=True) CurrentPage = 1 - savefilmres, PageLen = await getDataSavefilm21(pesan, kueri, CurrentPage) + savefilmres, PageLen, btn = await getDataSavefilm21(pesan, kueri, CurrentPage) if not savefilmres: return keyboard = InlineKeyboard() keyboard.paginate(PageLen, CurrentPage, 'page_savefilm#{number}' + f'#{pesan.id}#{message.from_user.id}') + keyboard.row(InlineButton("šŸ‘‡ Extract Data ", "Hmmm")) + keyboard.row(*btn) keyboard.row( InlineButton("āŒ Close", f"close#{message.from_user.id}") ) @@ -521,7 +523,7 @@ async def nodrakor_s(client, message): kueri = ' '.join(message.command[1:]) if not kueri: kueri = "" - pesan = await message.reply("ā³ Please wait, scraping data from Nodrakor..", quote=True) + pesan = await kirimPesan(message, "ā³ Please wait, scraping data from Nodrakor..", quote=True) CurrentPage = 1 nodrakorres, PageLen = await getDataNodrakor(pesan, kueri, CurrentPage) if not nodrakorres: return @@ -538,7 +540,7 @@ async def kusonime_s(client, message): kueri = ' '.join(message.command[1:]) if not kueri: kueri = "" - pesan = await message.reply("ā³ Please wait, scraping data from Kusonime..", quote=True) + pesan = await kirimPesan(message, "ā³ Please wait, scraping data from Kusonime..", quote=True) CurrentPage = 1 kusores, PageLen = await getDataKuso(pesan, kueri, CurrentPage) if not kusores: return @@ -555,7 +557,7 @@ async def lendrive_s(client, message): kueri = ' '.join(message.command[1:]) if not kueri: kueri = "" - pesan = await message.reply("ā³ Please wait, scraping data from Lendrive..", quote=True) + pesan = await kirimPesan(message, "ā³ Please wait, scraping data from Lendrive..", quote=True) CurrentPage = 1 lendres, PageLen = await getDataLendrive(pesan, kueri, CurrentPage) if not lendres: return @@ -572,7 +574,7 @@ async def movieku_s(client, message): kueri = ' '.join(message.command[1:]) if not kueri: kueri = "" - pesan = await message.reply("ā³ Please wait, scraping data from Movieku..", quote=True) + pesan = await kirimPesan(message, "ā³ Please wait, scraping data from Movieku..", quote=True) CurrentPage = 1 moviekures, PageLen = await getDataMovieku(pesan, kueri, CurrentPage) if not moviekures: return