commit b28f696e5e8f1d7a3c42695c57a2da592e032489 Author: Pakobbix Date: Sun Feb 19 15:18:28 2023 +0100 first iteration diff --git a/chromedriver.exe b/chromedriver.exe new file mode 100644 index 0000000..4029330 Binary files /dev/null and b/chromedriver.exe differ diff --git a/honeygaingift.py b/honeygaingift.py new file mode 100644 index 0000000..c1361dd --- /dev/null +++ b/honeygaingift.py @@ -0,0 +1,151 @@ +import platform +import subprocess +from selenium import webdriver +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.common.exceptions import TimeoutException +from selenium.webdriver.common.action_chains import ActionChains +import json +import time +import logging + +# now we will Create and configure logger +logging.basicConfig(filename="claim.log", + format='%(asctime)s %(message)s', + filemode='w') + +# Creates an object +logger = logging.getLogger() + +# Set logging level +logger.setLevel(logging.INFO) + +# Load username and password from JSON file +with open('honeygainlogin.json', 'r') as file: + login_data = json.load(file) + +username = login_data['username'] +password = login_data['password'] + +# Set the path to the Chrome binary +# Determine the path to the Chrome binary based on the operating system +if platform.system() == 'Windows': + chrome_binary = r'C:\Program Files\Google\Chrome\Application\chrome.exe' +else: + chrome_binary = '/usr/bin/google-chrome' + +# Set the Chrome options to use the binary and run in headless mode +chrome_options = webdriver.ChromeOptions() +chrome_options.add_experimental_option('excludeSwitches', ['enable-logging']) +chrome_options.binary_location = chrome_binary +chrome_options.add_argument('--headless') +#chrome_options.add_argument('--log-level=3') +#chrome_options.add_argument('--silent') + +""" +Start the ChromeDriver process with stdout +and stderr redirected to /dev/null or subprocess.DEVNULL +""" +if platform.system() == 'Windows': + devnull = subprocess.DEVNULL +else: + devnull = open('/dev/null', 'w') +process = subprocess.Popen(['chromedriver'], stdout=devnull, stderr=devnull) + +# Create a new Chrome driver using chromedriver and the Chrome options +driver = webdriver.Chrome(options=chrome_options) + +# Set the window size to 2560x1440 pixels +driver.set_window_size(2560, 1440) + +# logger.info("Check for Honeygain Luckypot") + +# Navigate to the login page +driver.get('https://dashboard.honeygain.com/login') + +try: + # Wait for the login button + WebDriverWait(driver, 10).until(EC.presence_of_element_located( + (By.XPATH, "//button[contains(., 'Login with email')]")) + ) +except TimeoutException: + print("Timeout: Failed to load page within 10 seconds") + logger.error("Timeout: Failed to load page within 10 seconds") + driver.quit() + +# Find username and password fields and enter login credentials +username_field = driver.find_element(By.ID, 'email') +username_field.send_keys(username) + +password_field = driver.find_element(By.ID, 'password') +password_field.send_keys(password) + +time.sleep(3) + +# logger.info("Login to Honeygain") + +# Click the login button to submit the form +submit_button = driver.find_element( + By.XPATH, "//button[contains(., 'Login with email')]" + ) +driver.execute_script("arguments[0].scrollIntoView(true);", submit_button) +submit_button.click() +actions = ActionChains(driver) +actions.move_to_element(submit_button).click().perform() + +try: + # Wait for the "Earned today" section to be present on the page + WebDriverWait(driver, 10).until(EC.presence_of_element_located( + (By.XPATH, "//div[contains(text(), 'Total earnings')]")) + ) +except TimeoutException: + print("Timeout: Failed to load page within 10 seconds") + logger.error("Timeout: Failed to load page within 10 seconds") + driver.quit() + +# Click on Cookie Banner +cookie_button = driver.find_element( + By.XPATH, "//button[contains(., 'Accept selected')]" + ) +cookie_button.click() + +try: + timer = WebDriverWait(driver, 10).until( + EC.presence_of_element_located( + (By.CSS_SELECTOR, 'div.sc-cUEOzv.kryQIl.sc-hshgAP.jDPslO'))) + + # If the countdown element is present, get the current time and print it + current_time = driver.find_element( + By.CSS_SELECTOR, 'p.sc-jOiSOi.jgbyVL' + ).text + print('Nächster Pot Verfügbar in:', current_time) + logger.info("Nächster Pot Verfügbar in: %s", current_time) +except TimeoutException: + # If the timer element is not present, click on the lucky pot button + try: + # Wait for the "Open Lucky Pot" button to be present on the page + WebDriverWait(driver, 10).until(EC.presence_of_element_located( + (By.XPATH, "//span[contains(text(), 'Open Lucky Pot')]")) + ) + logger.info('Öffne den Luckypot') + # Find the "Open Lucky Pot" button and click it + lucky_pot_button = driver.find_element( + By.XPATH, + "//span[contains(text(), 'Open Lucky Pot')]/ancestor::button" + ) + lucky_pot_button.click() + logger.info('Glückwunsch! Ich habe für dich gerade den Lucky Pot geöffnet') + except TimeoutException: + print("The 'Open Lucky Pot' button was not found. Exiting...") + logger.error("The 'Open Lucky Pot' button was not found. Exiting...") + driver.quit() + +# Close the browser window +driver.quit() + +process.terminate() + +# Close the /dev/null file on Unix/Linux +if not platform.system() == 'Windows': + devnull.close() diff --git a/honeygainlogin.json b/honeygainlogin.json new file mode 100644 index 0000000..264ad0f --- /dev/null +++ b/honeygainlogin.json @@ -0,0 +1,5 @@ +{ + "username": "", + "password": "" +} + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..db68c87 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +###### Requirements without Version Specifiers ###### + +selenium