diff --git a/honeygaingift.py b/honeygaingift.py index c1361dd..b37cfb3 100644 --- a/honeygaingift.py +++ b/honeygaingift.py @@ -1,3 +1,10 @@ +#!/usr/bin/python3 + +import os +import sys +import json +import time +import logging import platform import subprocess from selenium import webdriver @@ -6,13 +13,15 @@ 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 + +# Get the directory of the currently executing script +script_dir = os.path.dirname(os.path.realpath(sys.argv[0])) # now we will Create and configure logger -logging.basicConfig(filename="claim.log", +log_file = os.path.join(script_dir, 'claim.log') +logging.basicConfig(filename=log_file, format='%(asctime)s %(message)s', + datefmt='%d.%m.%Y %H:%M:%S', filemode='w') # Creates an object @@ -22,7 +31,9 @@ logger = logging.getLogger() logger.setLevel(logging.INFO) # Load username and password from JSON file -with open('honeygainlogin.json', 'r') as file: +json_file = os.path.join(script_dir, 'honeygainlogin.json') + +with open(json_file, 'r') as file: login_data = json.load(file) username = login_data['username'] @@ -40,8 +51,6 @@ 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 @@ -51,7 +60,7 @@ if platform.system() == 'Windows': devnull = subprocess.DEVNULL else: devnull = open('/dev/null', 'w') -process = subprocess.Popen(['chromedriver'], stdout=devnull, stderr=devnull) +process = subprocess.Popen(['/usr/local/bin/chromedriver'], stdout=devnull, stderr=devnull) # Create a new Chrome driver using chromedriver and the Chrome options driver = webdriver.Chrome(options=chrome_options) @@ -59,8 +68,6 @@ 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') @@ -70,7 +77,6 @@ try: (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() @@ -100,7 +106,6 @@ try: (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() @@ -119,7 +124,6 @@ try: 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 @@ -137,7 +141,6 @@ except TimeoutException: 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()