From 7787624723f1981bb597baa8764ffae6296295e5 Mon Sep 17 00:00:00 2001 From: WJC_Jr <54005049+WillCaton2350@users.noreply.github.com> Date: Wed, 25 Sep 2024 15:35:25 -0400 Subject: [PATCH 1/4] Add files via upload --- Python-Rumble-Bot-Final-Bot/bot/main.py | 47 +++++++++++++++++++ .../config/__init__.py | 0 Python-Rumble-Bot-Final-Bot/config/data.py | 23 +++++++++ Python-Rumble-Bot-Final-Bot/requirements.txt | 4 ++ Python-Rumble-Bot-Final-Bot/root.py | 44 +++++++++++++++++ 5 files changed, 118 insertions(+) create mode 100644 Python-Rumble-Bot-Final-Bot/bot/main.py create mode 100644 Python-Rumble-Bot-Final-Bot/config/__init__.py create mode 100644 Python-Rumble-Bot-Final-Bot/config/data.py create mode 100644 Python-Rumble-Bot-Final-Bot/requirements.txt create mode 100644 Python-Rumble-Bot-Final-Bot/root.py 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-Final-Bot/requirements.txt b/Python-Rumble-Bot-Final-Bot/requirements.txt new file mode 100644 index 0000000..aa7dade --- /dev/null +++ b/Python-Rumble-Bot-Final-Bot/requirements.txt @@ -0,0 +1,4 @@ +selenium==4.17.2 +fake-useragent==1.5.1 +undetected-chromedriver==3.5.5 +seleniumbase==4.24.11 \ No newline at end of file diff --git a/Python-Rumble-Bot-Final-Bot/root.py b/Python-Rumble-Bot-Final-Bot/root.py new file mode 100644 index 0000000..826b30d --- /dev/null +++ b/Python-Rumble-Bot-Final-Bot/root.py @@ -0,0 +1,44 @@ +from bot.main import web_driver +from config.data import nums + +class node: + def __init__(self,_): + self.data = self.activate() + self.left = None + self.right = None + + def activate(self): + for i in range(nums.num_nodes): + func = web_driver() + func.start_driver() + func.start_browser() + func.close_browser() + + + +class binary_tree: + global stack + global result + stack = [] + result = [] + + def main(self, root:node): + # in order traversal + 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 + print(f'Node: {node}') + return result + +if __name__ == "__main__": + try: + instance = binary_tree() + root = node(1) + except KeyboardInterrupt: + print("exiting gracefully...") + exit(0) + \ No newline at end of file From 04865ae2a039e34631ad76970911e68cb9345e87 Mon Sep 17 00:00:00 2001 From: WJC_Jr <54005049+WillCaton2350@users.noreply.github.com> Date: Wed, 25 Sep 2024 15:36:01 -0400 Subject: [PATCH 2/4] Delete Python-Rumble-Bot directory --- Python-Rumble-Bot/Dockerfile | 25 --------- Python-Rumble-Bot/bot/main.py | 82 ---------------------------- Python-Rumble-Bot/config/__init__.py | 1 - Python-Rumble-Bot/config/data.py | 30 ---------- Python-Rumble-Bot/docker-compose.yml | 6 -- Python-Rumble-Bot/requirements.txt | 4 -- Python-Rumble-Bot/root.py | 51 ----------------- 7 files changed, 199 deletions(-) delete mode 100644 Python-Rumble-Bot/Dockerfile delete mode 100644 Python-Rumble-Bot/bot/main.py delete mode 100644 Python-Rumble-Bot/config/__init__.py delete mode 100644 Python-Rumble-Bot/config/data.py delete mode 100644 Python-Rumble-Bot/docker-compose.yml delete mode 100644 Python-Rumble-Bot/requirements.txt delete mode 100644 Python-Rumble-Bot/root.py 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/Python-Rumble-Bot/requirements.txt b/Python-Rumble-Bot/requirements.txt deleted file mode 100644 index aa7dade..0000000 --- a/Python-Rumble-Bot/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -selenium==4.17.2 -fake-useragent==1.5.1 -undetected-chromedriver==3.5.5 -seleniumbase==4.24.11 \ No newline at end of file diff --git a/Python-Rumble-Bot/root.py b/Python-Rumble-Bot/root.py deleted file mode 100644 index 1857b59..0000000 --- a/Python-Rumble-Bot/root.py +++ /dev/null @@ -1,51 +0,0 @@ -from bot.main import web_driver -from config.data import nums - -class node: - def __init__(self,_): - self.data = self.activate() - self.left = None - self.right = None - - def activate(self): - func = web_driver() - func.start_driver() - func.start_browser() - func.close_browser() - -class binary_tree: - global stack - global result - stack = [] - result = [] - - def main(self, root:node): - # in order traversal - while root is not None or stack != []: - while root is not None: - stack.append(root) - root = root.left - root = stack.pop() - self.activate() - result.append(root.data) - root = root.right - print(f'Node: {node}') - return result - -if __name__ == "__main__": - 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) From e8632d2b01a47d4d2fab9cd0121c85fd415f2c8e Mon Sep 17 00:00:00 2001 From: WJC_Jr <54005049+WillCaton2350@users.noreply.github.com> Date: Wed, 25 Sep 2024 15:37:26 -0400 Subject: [PATCH 3/4] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index aefc519..32f39cc 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,10 @@ https://www.python.org/downloads/ Dependencies: -seleniumbase==4.23.7 +selenium==4.17.2 fake-useragent==1.5.1 +undetected-chromedriver==3.5.5 +seleniumbase==4.24.11 License From 2f294c30d58bf3e5c3e4314d4b32223a047df722 Mon Sep 17 00:00:00 2001 From: WJC_Jr <54005049+WillCaton2350@users.noreply.github.com> Date: Wed, 25 Sep 2024 15:38:31 -0400 Subject: [PATCH 4/4] Update README.md --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 32f39cc..99ce506 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,7 @@ https://www.python.org/downloads/ Dependencies: -selenium==4.17.2 -fake-useragent==1.5.1 -undetected-chromedriver==3.5.5 -seleniumbase==4.24.11 +see - requirements.txt License