#!/usr/bin/env python3
""" This is a script will vote in this page and it will test it """

from selenium.webdriver.chrome.options import Options
# to change the User-Agent in Chrome
from selenium import webdriver


browser = webdriver.Chrome()
opts = Options()
opts.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36")

id = "1565" # my id

def votes_levl(identi):
    browser.find_element_by_name("id").send_keys(id)
    browser.find_element_by_name("holdthedoor").click()
    
def restart():
    opts = Options()
    opts.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36")
    browser = webdriver.Chrome(chrome_options=opts)
    browser.get('http://158.69.76.135/level2.php')
    

def reque_votes(total, num, id, i):
    if num < 1024:
        for _ in range(total):
            try:
                votes_levl(id)
            except Exception as e:
                print("NOooo....", i)
                if i < num:
                    restart()
                    reque_votes(num, id, 0)
            finally:
                num -= 1

total = 2000      
reque_votes(total, 2000, id, 0)
