From 59cedd1417629ff31f77273812c0a31dac70c909 Mon Sep 17 00:00:00 2001 From: SAF ONE <77989182+AsmSafone@users.noreply.github.com> Date: Wed, 9 Feb 2022 21:27:58 +0600 Subject: [PATCH] minor fixes in logo_maker (#251) * fix * some fixes * forgot comment Co-authored-by: Krishna-singhal <65902764+Krishna-Singhal@users.noreply.github.com> --- plugins/logo_maker.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/plugins/logo_maker.py b/plugins/logo_maker.py index 91d613408..49c7895e7 100644 --- a/plugins/logo_maker.py +++ b/plugins/logo_maker.py @@ -2,10 +2,10 @@ # Logo maker using brandcrowd.com import os -from typing import List, Tuple - +import shutil import aiohttp import aiofiles +from typing import List, Tuple from bs4 import BeautifulSoup from pyrogram.types import InputMediaPhoto @@ -13,7 +13,7 @@ from userge import userge, Message LOG = userge.getLogger(__name__) -STATUS = {} +STATUS = False URI = "https://www.brandcrowd.com/maker/logos" HEADERS = {"User-Agent": 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) ' 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37' @@ -54,11 +54,12 @@ async def download(uri: str, file_name: str): async def dispatch(message: Message, logos: List[Tuple[str]]): """ dispatch logos to chat """ + global STATUS # pylint: disable=global-statement group: List[InputMediaPhoto] = [] paths: List[str] = [] src: str = "Source: Here" count: int = 1 - file_name: str = "logo_{}.jpg" + file_name: str = "temp_logos/logo_{}.jpg" status = await message.edit("`Beginning To Dispatch Content...`") batch = 1 for logo in logos: @@ -69,7 +70,8 @@ async def dispatch(message: Message, logos: List[Tuple[str]]): group.append(InputMediaPhoto(loc, caption=src.format(source))) if len(group) == 10: try: - await status.edit(f"`Uploading Batch {batch}...`") + await status.edit( + f"`Uploading Batch {batch}/{round(len(logos) / 10)}...`") await message.reply_media_group(group) except Exception as pyro: LOG.exception(pyro) @@ -80,15 +82,15 @@ async def dispatch(message: Message, logos: List[Tuple[str]]): LOG.exception(e) if len(group) >= 2: - await status.edit(f"`Uploading Batch {batch}`") + await status.edit( + f"`Uploading Batch {batch}/{round(len(logos)/10)}`") await message.reply_media_group(group) elif len(group) == 1: await message.reply_photo(group[0].media, caption=group[0].caption) - STATUS[""] = False - for path in paths: - if os.path.lexists(path): - os.remove(path) await status.delete() + STATUS = False + if os.path.exists("temp_logos/"): + shutil.rmtree("temp_logos/", ignore_errors=True) @userge.on_cmd("logo", about={ @@ -100,9 +102,10 @@ async def dispatch(message: Message, logos: List[Tuple[str]]): }) async def jv_logo_maker(message: Message): """ make logos """ - if STATUS.get("", False): + global STATUS # pylint: disable=global-statement + if STATUS: return await message.err("Let the current process be completed!!") - STATUS[""] = True + STATUS = True jv_text = message.input_str if not jv_text: return await message.err("Input Required!!") @@ -112,11 +115,10 @@ async def jv_logo_maker(message: Message): type_text = jv_text if ':' in jv_text: type_text, type_keyword = jv_text.split(":", 1) - try: logos = await logo_maker(type_text, type_keyword) except Exception as e: LOG.exception(e) - await message.err("No Logos for Ya 😒😒😏") - return + STATUS = False + return await message.err("No Logos for Ya 😒😒😏") await dispatch(message, logos)