Skip to content

Commit

Permalink
Update root.py
Browse files Browse the repository at this point in the history
  • Loading branch information
WillCaton2350 authored Jul 31, 2024
1 parent b6e31e0 commit 5b28a92
Showing 1 changed file with 88 additions and 38 deletions.
126 changes: 88 additions & 38 deletions Python-Rumble-Bot-Final/root.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,92 @@
from bot.main import web_driver
from config.data import nums
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait as WDW
from selenium.common.exceptions import NoSuchElementException
from undetected_chromedriver.options import ChromeOptions
from selenium.webdriver.common.by import By
import undetected_chromedriver as uc
from urllib.error import HTTPError
from random import randint
from config.data import *
import logging
import ssl

class node:
def __init__(self,_):
self.data = self.activate()
self.left = None
self.right = None
class web_driver:
def __init__(self):
self.driver = None

def start_driver(self):
ssl._create_default_https_context = ssl._create_unverified_context
options = ChromeOptions()
options.add_argument("--single-process")
options.add_argument("--headless")
options.add_argument("--incognito")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--disable-cache")
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_argument("--no-sandbox")
options.add_argument("--mute-audio")
self.driver = uc.Chrome(options=options)
user_agent = useragents.ua.random
self.driver.execute_cdp_cmd(
f"Network.setUserAgentOverride",
{"userAgent":user_agent})
return self.driver

def start_browser(self):
for i in urls.url_dict:
value = urls.url_dict[i]
while nums.retries < nums.max_retries:
try:
self.driver.get(value)
WDW(self.driver, 10).until(EC.url_to_be(value))
try:
WDW(self.driver,10).until(
EC.presence_of_element_located((
By.XPATH,locators.play_btn_xpath
)))
self.driver.find_element(
By.XPATH,locators.play_btn_xpath).click()
time_altered.time_buffer(2)
except NoSuchElementException as err:
if err:
logging.error(f'NoSuchElementException: {err}')
logging.info(f"Retrying Element in {nums.retry_delay} seconds...")
nums.retry_delay = self.fibonacci(nums.retry_delay)
nums.retries += 1
break
except HTTPError as err:
if err.code != nums.status:
logging.error(f"HTTP error occurred: {err}")
logging.info(f"Retrying in {nums.retry_delay} seconds...")
nums.retry_delay = self.fibonacci(nums.retry_delay)
nums.retries += 1
@staticmethod
def fibonacci(n):
if n <= 0:
return []
elif n == 1:
return [0]
elif n == 2:
return [0, 1]
else:
sequence = [0, 1]
for i in range(2, n):
random_increment = randint(1, 5)
next_number = sequence[-1] + sequence[-2] + random_increment
sequence.append(next_number)
return sequence
n = 10
fibonacci_sequence = fibonacci(n)

def quit_driver(self):
self.driver.close()

def activate(self):
for i in range(nums.num_executions):
func = web_driver()
func.start_driver()
func.start_browser()
func.quit_driver()
print(f'node:{node} {i}')

class binary_tree:
global stack
global result
stack = []
result = []
def main(self,root:node):
while root is not None or stack != []:
while root is not None:
stack.append(root)
root = root.left
root = stack.pop()
result.append(root.data)
root = root.right
return result

if __name__ == "__main__":
try:
instance = binary_tree()
root = node(1)
root.left = node(2)
root.right = node(3)
instance.main(root=root)
except KeyboardInterrupt:
print(' exiting gracefully...')
exit(0)
for i in range(nums.num_executions):
func = web_driver()
func.start_driver()
func.start_browser()
func.quit_driver()
print(f'node: web_driver activated')

0 comments on commit 5b28a92

Please sign in to comment.