diff --git a/Python-Rumble-Bot-Final-Bot/bot/main.py b/Python-Rumble-Bot-Final-Bot/bot/main.py new file mode 100644 index 0000000..d299c00 --- /dev/null +++ b/Python-Rumble-Bot-Final-Bot/bot/main.py @@ -0,0 +1,47 @@ +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 config.data import urls, locators, useragents, time_buffer +from selenium.webdriver.common.by import By +from urllib.error import HTTPError +from seleniumbase import Driver +import logging + +class web_driver: + def __init__(self): + self.driver = None + + def start_driver(self): + self.driver = Driver(uc=True) + 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] + 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.CLASS_NAME,locators.play_btn_classname + ))) + self.driver.find_element( + By.CLASS_NAME,locators.play_btn_classname).click() + time_buffer.time_altered(1) + except NoSuchElementException as err: + if err: + logging.error(f'NoSuchElementException: {err}') + + except HTTPError as err: + if err.code != 200: + logging.error(f"HTTP error occurred: {err}") + + + def close_browser(self): + self.driver.quit() \ No newline at end of file diff --git a/Python-Rumble-Bot-Final-Bot/config/__init__.py b/Python-Rumble-Bot-Final-Bot/config/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Python-Rumble-Bot-Final-Bot/config/data.py b/Python-Rumble-Bot-Final-Bot/config/data.py new file mode 100644 index 0000000..af8d0ac --- /dev/null +++ b/Python-Rumble-Bot-Final-Bot/config/data.py @@ -0,0 +1,23 @@ +from dataclasses import dataclass +from fake_useragent import UserAgent +from time import sleep + +@dataclass +class nums: + num_nodes: int = 10 + +class time_buffer: + time_altered = sleep + +class urls: + url_dict = { + 1:'www.example.com/', + 2:'', + } + +class locators: + play_btn_classname: str = 'bigPlayUIInner' + + +class useragents: + ua = UserAgent() \ No newline at end of file diff --git a/Python-Rumble-Bot/requirements.txt b/Python-Rumble-Bot-Final-Bot/requirements.txt similarity index 100% rename from Python-Rumble-Bot/requirements.txt rename to Python-Rumble-Bot-Final-Bot/requirements.txt diff --git a/Python-Rumble-Bot/root.py b/Python-Rumble-Bot-Final-Bot/root.py similarity index 65% rename from Python-Rumble-Bot/root.py rename to Python-Rumble-Bot-Final-Bot/root.py index 1857b59..826b30d 100644 --- a/Python-Rumble-Bot/root.py +++ b/Python-Rumble-Bot-Final-Bot/root.py @@ -8,10 +8,13 @@ def __init__(self,_): self.right = None def activate(self): - func = web_driver() - func.start_driver() - func.start_browser() - func.close_browser() + for i in range(nums.num_nodes): + func = web_driver() + func.start_driver() + func.start_browser() + func.close_browser() + + class binary_tree: global stack @@ -26,7 +29,6 @@ def main(self, root:node): stack.append(root) root = root.left root = stack.pop() - self.activate() result.append(root.data) root = root.right print(f'Node: {node}') @@ -36,16 +38,7 @@ def main(self, root:node): try: instance = binary_tree() root = node(1) - root.left = node(2) - root.right = node(3) - root.left.left = node(4) - root.left.right = node(5) - root.right.left = node(6) - root.right.right = node(7) - for i in range(nums.num_nodes): - traversal = instance.main(root=root) - print(f'Traversal Pattern: {val}') - print(f'Execution: {i}') except KeyboardInterrupt: print("exiting gracefully...") exit(0) + \ No newline at end of file diff --git a/Python-Rumble-Bot/Dockerfile b/Python-Rumble-Bot/Dockerfile deleted file mode 100644 index 604e0a7..0000000 --- a/Python-Rumble-Bot/Dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -# Specify a base image. This comes from Docker Hub. -FROM python:3.12.2-alpine - -# ENV sets environment variables in the Docker container. -# PYTHONUNBUFFERED ensures that Python outputs are sent straight to terminal without being buffered. -ENV PYTHONUNBUFFERED=1 - -RUN apk update && \ - apk add --no-cache \ - chromium \ - chromium-chromedriver && \ - rm -rf /var/cache/apk/* - -WORKDIR /app - -COPY . /app - -# Copies the requirements.txt from your local directory to the Docker image. -COPY ./requirements.txt /requirements.txt - -# Then run pip install to install all dependencies listed in requirements.txt. -RUN pip install -r /requirements.txt - -# Specifies the command to run when the Docker container starts. -CMD ["python3", "root.py","--headless"] \ No newline at end of file diff --git a/Python-Rumble-Bot/bot/main.py b/Python-Rumble-Bot/bot/main.py deleted file mode 100644 index 1f59176..0000000 --- a/Python-Rumble-Bot/bot/main.py +++ /dev/null @@ -1,82 +0,0 @@ -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 config.data import urls, nums, locators, useragents, time_altered -from selenium.webdriver.common.by import By -import undetected_chromedriver as uc -from urllib.error import HTTPError -from random import randint -import logging -import ssl - -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("--disable-blink-features=AutomaionControlled") - options.add_argument("--disable-dev-shm-usage") - options.add_argument("--single-process") - options.add_argument("--disable-cache") - options.add_argument("--no-sandbox") - options.add_argument("--mute-audio") - options.add_argument("--incognito") - options.add_argument("--headless") - self.driver = uc.Chrome(options=options) - user_agent = useragents.ua.random - self.driver.execute_cdp_cmd( - '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(1) - 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 - - 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 close_browser(self): - self.driver.close() diff --git a/Python-Rumble-Bot/config/__init__.py b/Python-Rumble-Bot/config/__init__.py deleted file mode 100644 index 0519ecb..0000000 --- a/Python-Rumble-Bot/config/__init__.py +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/Python-Rumble-Bot/config/data.py b/Python-Rumble-Bot/config/data.py deleted file mode 100644 index 1e4bcf3..0000000 --- a/Python-Rumble-Bot/config/data.py +++ /dev/null @@ -1,30 +0,0 @@ -from dataclasses import dataclass -from fake_useragent import UserAgent -from time import sleep - -@dataclass -class nums: - num_nodes: int = 100 - node_data: int = 0 - max_retries:int = 3 - retry_delay: int = 0 - retries: int = 0 - status: int = 200 - num_executions: int = 10 - -@dataclass -class urls: - main_url: str = 'https://www.example.com' - - url_dict = { - 1:'https:/www.example.com', - } - -class locators: - play_btn_xpath: str = '/html/body/main/article/div[2]/div/div[1]/div[1]/div/div/div[1]/div' - -class useragents: - ua = UserAgent() - -class time_altered: - time_buffer = sleep \ No newline at end of file diff --git a/Python-Rumble-Bot/docker-compose.yml b/Python-Rumble-Bot/docker-compose.yml deleted file mode 100644 index 2bb32f5..0000000 --- a/Python-Rumble-Bot/docker-compose.yml +++ /dev/null @@ -1,6 +0,0 @@ -version: '25.0' - -services: - selenium: - image: python-selenium-rumble-bot:latest - build: . \ No newline at end of file diff --git a/README.md b/README.md index aefc519..99ce506 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,7 @@ https://www.python.org/downloads/ Dependencies: -seleniumbase==4.23.7 -fake-useragent==1.5.1 +see - requirements.txt License