Co-authored-by: Aakash <BLUE-DEVIL1134@users.noreply.github.com> Co-authored-by: Aditya <me@xditya.me> Co-authored-by: Danish <danish@ultroid.tech> Co-authored-by: buddhhu <buddhuu@users.noreply.github.com> Co-authored-by: sppidy <sppidy@users.noreply.github.com> Co-authored-by: Arnab Paryali <Arnabxd@users.noreply.github.com> Co-authored-by: divkix <divkix@users.noreply.github.com> Co-authored-by: hellboi_atul <hellboi-atul@users.noreply.github.com> Co-authored-by: Programming Error <error@notavailable.live> Co-authored-by: New-dev0 <New-dev0@notavailable.live>
60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
# Ultroid - UserBot
|
|
# Copyright (C) 2020 TeamUltroid
|
|
#
|
|
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
|
|
# PLease read the GNU Affero General Public License in
|
|
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
|
|
|
|
"""
|
|
✘ Commands Available -
|
|
|
|
• {i}unsplash <search query> ; <no of pics>
|
|
Unsplash Image Search.
|
|
|
|
"""
|
|
|
|
|
|
import urllib
|
|
|
|
import requests as r
|
|
from bs4 import BeautifulSoup as bs
|
|
|
|
from . import *
|
|
|
|
|
|
@ultroid_cmd(pattern="unsplash ?(.*)")
|
|
async def searchunsl(ult):
|
|
match = ult.pattern_match.group(1)
|
|
if not match:
|
|
return await eor(ult, "Give me Something to Search")
|
|
if ";" in match:
|
|
num = int(match.split(";")[1])
|
|
query = match.split(";")[0]
|
|
else:
|
|
num = 5
|
|
query = match
|
|
tep = await eor(ult, "`Processing... `")
|
|
res = autopicsearch(query)
|
|
if len(res) == 0:
|
|
return await eod(ult, "No Results Found !")
|
|
qas = res[:num]
|
|
dir = "resources/downloads"
|
|
CL = []
|
|
nl = 0
|
|
for rp in qas:
|
|
li = "https://unsplash.com" + rp["href"]
|
|
ct = r.get(li).content
|
|
bst = bs(ct, "html.parser", from_encoding="utf-8")
|
|
ft = bst.find_all("img", "_2UpQX")[0]["src"]
|
|
Hp = dir + "img" + f"{nl}.png"
|
|
urllib.request.urlretrieve(ft, Hp)
|
|
CL.append(Hp)
|
|
nl += 1
|
|
await bot.send_file(
|
|
ult.chat_id, CL, caption=f"Uploaded {len(qas)} Images\n", album=True
|
|
)
|
|
await tep.delete()
|
|
|
|
|
|
HELP.update({f"{__name__.split('.')[1]}": f"{__doc__.format(i=HNDLR)}"})
|