import time
import bs4
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from discord_webhook import DiscordWebhook, DiscordEmbed
webhookUrl = "Your Webhook URL"
webhook = DiscordWebhook(url = webhookUrl, content = "Bağlantı Başarılı")
response = webhook.execute()

opts = Options()
driver = webdriver.Chrome(options = opts)

targetProduct1 = "Vatan Bilgisayar 1.Ürün"
targetProduct2 = "Vatan Bilgisayar 2.Ürün"
target1 = [targetProduct1, 0, 0]
target2 = [targetProduct2, 0, 0]

loopCount = 0
def stockController(target):
    global loopCount
    x = loopCount
    x = x + 1
    loopCount = x
    print(("Loop = " + str(x)))
    driver.get(target[0])
    html = driver.page_source
    soup = bs4.BeautifulSoup(html, "html.parser")

    buttons = soup.find_all("button", {"class" : "btn-success"})
    productName = soup.find("h1", {"class" : "product-list__product-name"})

    for button in buttons:
        if "SEPETE EKLE" in button.text:
            target[2] = 1
            if target[2] != target[1]:
                webhook = DiscordWebhook(url = webhookUrl, content = 'STOKLARDA = ' + target[0])
                productName = 'VATAN' + str(productName.text) + 'STOKLARDA'
                embed = DiscordEmbed(title = productName, description = target[0])
                webhook.add_embed(embed)
                response = webhook.execute()
                print("[!] STOKLARDA [!]" + productName.text)
                target[1] = target[2]
        else:
            target[1] = 0
            print(str(productName) + " [!] ÜRÜN STOKLARDA YOK [!]")

        print(target[0])
        print(target[1])
        print(target[2])

    shopButton = driver.find_element_by_class_name("stockBTN")
    shopButton.click()
    html_list = driver.find_element_by_id("storeList")
    shops = html_list.find_element_by_tag_name("li")

    for shop in shops:
        print("[!] MAĞAZA STOK [!] = " + shop.text)
        webhook = DiscordWebhook(url = webhookUrl, content = 'STOKLARDA = ' + target[0])
        productName = '[!] MAĞAZA STOK TESPİT EDİLDİ [!] = ' + shop.text + str(productName.text)
        embed = DiscordEmbed(title = productName, description = target[0])
        webhook.add_embed(embed)
        response = webhook.execute()

while True:
    stockController(target1)
    time.sleep(15)
    stockController(target2)
    time.sleep(15)