Skip to content

Commit

Permalink
Update carbon.py
Browse files Browse the repository at this point in the history
  • Loading branch information
xditya authored Aug 27, 2020
1 parent 1e32e4e commit 7d79471
Showing 1 changed file with 21 additions and 33 deletions.
54 changes: 21 additions & 33 deletions userbot/plugins/carbon.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
""" Userbot module containing various scrapers. """

import os
import shutil
from bs4 import BeautifulSoup
import re
import random
from time import sleep
from html import unescape
from re import findall
from datetime import datetime
from selenium import webdriver
from urllib.parse import quote_plus
from urllib.error import HTTPError
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.chrome.options import Options
from wikipedia import summary
Expand All @@ -25,35 +24,28 @@
from gtts import gTTS
from emoji import get_emoji_regexp
from userbot import CMD_HELP, BOTLOG, BOTLOG_CHATID, YOUTUBE_API_KEY, CHROME_DRIVER, GOOGLE_CHROME_BIN
from userbot.utils import admin_cmd

from userbot.utils import register

CARBONLANG = "auto"
LANG = "en"


@borg.on(admin_cmd(pattern="carbon"))
@register(outgoing=True, pattern="^.carbon")
async def carbon_api(e):
if not e.text[0].isalpha() and e.text[0] not in ("/", "#", "@", "!"):

""" A Wrapper for carbon.now.sh """
await e.edit("`Processing..`")
CARBON = 'https://carbon.now.sh/?l={lang}&code={code}'
global CARBONLANG
textx = await e.get_reply_message()
pcode = e.text

if pcode[8:]:
pcodee = str(pcode[8:])
if "|" in pcodee:
pcode, skeme = pcodee.split("|")
else:
pcode = pcodee
skeme = None
pcode = str(pcode[8:])
elif textx:
pcode = str(textx.message)
skeme = None # Importing message to module
pcode = str(textx.message) # Importing message to module

code = quote_plus(pcode) # Converting to urlencoded
await e.edit("`Making Carbon...\n25%`")
await e.edit("`Meking Carbon...\n25%`")
url = CARBON.format(code=code, lang=CARBONLANG)
chrome_options = Options()
chrome_options.add_argument("--headless")
Expand All @@ -71,34 +63,30 @@ async def carbon_api(e):
driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')
params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': download_path}}
command_result = driver.execute("send_command", params)
driver.find_element_by_xpath('/html/body/div[1]/main/div[3]/div[2]/div[1]/div[1]/div/span[2]').click()
if skeme != None:
k_skeme = driver.find_element_by_xpath('/html/body/div[1]/main/div[3]/div[2]/div[1]/div[1]/div/span[2]/input')
k_skeme.send_keys(skeme)
k_skeme.send_keys(Keys.DOWN)
k_skeme.send_keys(Keys.ENTER)
else:
color_scheme = str(random.randint(1,29))
driver.find_element_by_id(("downshift-0-item-" + color_scheme)).click()
driver.find_element_by_id("export-menu").click()
driver.find_element_by_xpath("//button[contains(text(),'4x')]").click()
driver.find_element_by_xpath("//button[contains(text(),'PNG')]").click()
driver.find_element_by_xpath("//button[contains(text(),'Export')]").click()

#driver.find_element_by_xpath("//button[contains(text(),'4x')]").click()

#driver.find_element_by_xpath("//button[contains(text(),'PNG')]").click()

await e.edit("`Processing..\n75%`")
# Waiting for downloading
sleep(2.5)
color_name = driver.find_element_by_xpath('/html/body/div[1]/main/div[3]/div[2]/div[1]/div[1]/div/span[2]/input').get_attribute('value')
await e.edit("`Done...\n100%`")
await e.edit("`Done Dana Done...\n100%`")

file = './carbon.png'
await e.edit("`Uploading..`")
await e.client.send_file(
e.chat_id,
file,
caption="<< `Here's your carbon!` >>\n**Colour Scheme: **`{}`".format(color_name),
caption="<<Carbonised 😁>>\n<<(c) @TeleBotSupport >>",
force_document=True,
reply_to=e.message.reply_to_msg_id,
)
os.remove('./carbon.png')
os.remove('./TeleBot.png')
driver.quit()
# Removing carbon.png after uploading

# Removing TeleBot.png after uploading

await e.delete() # Deleting msg

0 comments on commit 7d79471

Please sign in to comment.