Skip to content

Commit

Permalink
minor fixes in logo_maker (#251)
Browse files Browse the repository at this point in the history
* fix

* some fixes

* forgot comment

Co-authored-by: Krishna-singhal <[email protected]>
  • Loading branch information
AsmSafone and Krishna-Singhal authored Feb 9, 2022
1 parent 3d32e4f commit 59cedd1
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions plugins/logo_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
# 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

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'
Expand Down Expand Up @@ -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: <a href='https://www.brandcrowd.com{}'>Here</a>"
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:
Expand All @@ -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)
Expand All @@ -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={
Expand All @@ -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!!")
Expand All @@ -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)

0 comments on commit 59cedd1

Please sign in to comment.