resorted imports, fixed platforms to windows/linux (exclude mac), timer will be searched via string not class anymore (class = dynamic), added Winnings api call, added message if luckypot could be claimed, tell how much via api call and JWT Token
This commit is contained in:
parent
c4079a24b3
commit
ac55be6674
182
honeygaingift.py
182
honeygaingift.py
@ -1,10 +1,3 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import json
|
|
||||||
import time
|
|
||||||
import logging
|
|
||||||
import platform
|
import platform
|
||||||
import subprocess
|
import subprocess
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
@ -13,142 +6,157 @@ from selenium.webdriver.common.by import By
|
|||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
from selenium.common.exceptions import TimeoutException
|
from selenium.common.exceptions import TimeoutException
|
||||||
from selenium.webdriver.common.action_chains import ActionChains
|
from selenium.webdriver.common.action_chains import ActionChains
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
import logging
|
||||||
|
import requests
|
||||||
|
|
||||||
# Get the directory of the currently executing script
|
# Hier wird das logging erstmal auf Critical gestellt
|
||||||
|
logging.basicConfig(level=logging.CRITICAL)
|
||||||
|
|
||||||
|
# Speichere den absoluten Pfad zum Skript.
|
||||||
script_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
|
script_dir = os.path.dirname(os.path.realpath(sys.argv[0]))
|
||||||
|
|
||||||
# now we will Create and configure logger
|
# Erstelle logdatei & defeniert das format
|
||||||
log_file = os.path.join(script_dir, 'claim.log')
|
log_file = os.path.join(script_dir, 'claim.log')
|
||||||
logging.basicConfig(filename=log_file,
|
logging.basicConfig(filename=log_file,
|
||||||
format='%(asctime)s %(message)s',
|
format='%(asctime)s %(message)s',
|
||||||
datefmt='%d.%m.%Y %H:%M:%S',
|
datefmt='%d.%m.%Y %H:%M:%S',
|
||||||
filemode='w')
|
filemode='w')
|
||||||
|
|
||||||
# Creates an object
|
# Erstelle ein Aufrufbares Objekt.
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
# Set logging level
|
# Stelle das Log Level ein
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
# Load username and password from JSON file
|
# Lade die Logindaten aus der honeygainlogin.json datei.
|
||||||
json_file = os.path.join(script_dir, 'honeygainlogin.json')
|
with open('honeygainlogin.json', 'r') as file:
|
||||||
|
|
||||||
with open(json_file, 'r') as file:
|
|
||||||
login_data = json.load(file)
|
login_data = json.load(file)
|
||||||
|
|
||||||
username = login_data['username']
|
username = login_data['username']
|
||||||
password = login_data['password']
|
password = login_data['password']
|
||||||
|
|
||||||
# Set the path to the Chrome binary
|
# Nutze den vorinstallierten Chrome Browser
|
||||||
# Determine the path to the Chrome binary based on the operating system
|
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
chrome_binary = r'C:\Program Files\Google\Chrome\Application\chrome.exe'
|
chrome_binary = r'C:\Program Files\Google\Chrome\Application\chrome.exe' # Chrome EXE die genutzt werden soll in Windows
|
||||||
else:
|
elif platform.system() == 'Linux':
|
||||||
chrome_binary = '/usr/bin/google-chrome'
|
chrome_binary = '/usr/bin/google-chrome' # Chrome executable die genutzt werden soll in Linux
|
||||||
|
|
||||||
# Set the Chrome options to use the binary and run in headless mode
|
# Erstelle Chrome Argumente Variable
|
||||||
chrome_options = webdriver.ChromeOptions()
|
chrome_options = webdriver.ChromeOptions()
|
||||||
|
# Verhindert das der Chromedriver log angezeigt wird.
|
||||||
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
|
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
|
||||||
chrome_options.binary_location = chrome_binary
|
chrome_options.binary_location = chrome_binary
|
||||||
|
# Öffnet den Chrome im Headless modus (Ohne Fenster)
|
||||||
chrome_options.add_argument('--headless')
|
chrome_options.add_argument('--headless')
|
||||||
|
|
||||||
"""
|
# Erstelle eine Session mit Chrome und den vorher definierten Einstellungen
|
||||||
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(['/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)
|
driver = webdriver.Chrome(options=chrome_options)
|
||||||
|
|
||||||
# Set the window size to 2560x1440 pixels
|
"""
|
||||||
|
Öffne Chrome mit einer Auflösung von 2560x1440
|
||||||
|
|
||||||
|
Dies ist wichtig, da sonst die info mit dem Jumpcoin über der Login-Mail eingabe hängt und daher nicht klickbar ist.
|
||||||
|
"""
|
||||||
driver.set_window_size(2560, 1440)
|
driver.set_window_size(2560, 1440)
|
||||||
|
|
||||||
# Navigate to the login page
|
# Öffne die Loginseite
|
||||||
driver.get('https://dashboard.honeygain.com/login')
|
driver.get('https://dashboard.honeygain.com/login')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Wait for the login button
|
# Warte bis der Login Button verfügbar ist.
|
||||||
WebDriverWait(driver, 10).until(EC.presence_of_element_located(
|
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//button[contains(., 'Login with email')]")))
|
||||||
(By.XPATH, "//button[contains(., 'Login with email')]"))
|
|
||||||
)
|
|
||||||
except TimeoutException:
|
except TimeoutException:
|
||||||
logger.error("Timeout: Failed to load page within 10 seconds")
|
print("Timeout: Failed to load page within 10 seconds")
|
||||||
driver.quit()
|
driver.quit()
|
||||||
|
|
||||||
# Find username and password fields and enter login credentials
|
# Suche die Nutzernamen & Passwort felder und fülle diese aus.
|
||||||
username_field = driver.find_element(By.ID, 'email')
|
username_field = driver.find_element(By.ID, 'email')
|
||||||
username_field.send_keys(username)
|
username_field.send_keys(username)
|
||||||
|
|
||||||
password_field = driver.find_element(By.ID, 'password')
|
password_field = driver.find_element(By.ID, 'password')
|
||||||
password_field.send_keys(password)
|
password_field.send_keys(password)
|
||||||
|
|
||||||
|
# Zur Sicherheit ein 3 Sekunden Timer. Damit es nicht zu "bottig" wirkt.
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
# logger.info("Login to Honeygain")
|
# Drücke den Login Button, scrolle gegebenfalls etwas in dessen Richtung, um sicherzustellen, dass dieser drückbar ist.
|
||||||
|
submit_button = driver.find_element(By.XPATH, "//button[contains(., 'Login with email')]")
|
||||||
# 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)
|
driver.execute_script("arguments[0].scrollIntoView(true);", submit_button)
|
||||||
submit_button.click()
|
submit_button.click()
|
||||||
actions = ActionChains(driver)
|
actions = ActionChains(driver)
|
||||||
actions.move_to_element(submit_button).click().perform()
|
actions.move_to_element(submit_button).click().perform()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Wait for the "Earned today" section to be present on the page
|
# Warte max 10 Sekunden bis der Text "Total earnings" erscheint.
|
||||||
WebDriverWait(driver, 10).until(EC.presence_of_element_located(
|
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[contains(text(), 'Total earnings')]")))
|
||||||
(By.XPATH, "//div[contains(text(), 'Total earnings')]"))
|
|
||||||
)
|
|
||||||
except TimeoutException:
|
except TimeoutException:
|
||||||
logger.error("Timeout: Failed to load page within 10 seconds")
|
print("Timeout: Failed to load page within 10 seconds")
|
||||||
driver.quit()
|
driver.quit()
|
||||||
|
|
||||||
# Click on Cookie Banner
|
# Lasse den Cookie Banner verschwinden.
|
||||||
cookie_button = driver.find_element(
|
cookie_button = driver.find_element(By.XPATH, "//button[contains(., 'Accept selected')]")
|
||||||
By.XPATH, "//button[contains(., 'Accept selected')]"
|
|
||||||
)
|
|
||||||
cookie_button.click()
|
cookie_button.click()
|
||||||
|
|
||||||
|
# Versuche einen Timer ausfindig zu machen
|
||||||
try:
|
try:
|
||||||
timer = WebDriverWait(driver, 10).until(
|
# Warte 10 Sekunden ob ein Timer auftaucht mit dem text "hours" "min" and "sec"
|
||||||
EC.presence_of_element_located(
|
timer = WebDriverWait(driver, 10).until(EC.presence_of_element_located((
|
||||||
(By.CSS_SELECTOR, 'div.sc-cUEOzv.kryQIl.sc-hshgAP.jDPslO')))
|
By.XPATH, "//p[contains(., 'hours') and contains(., 'min') and contains(., 'sec')]")))
|
||||||
|
# Wenn der Timer aufgetaucht ist, finde die CSS Class und speicher diese als string.
|
||||||
|
current_time = driver.find_element(By.CSS_SELECTOR, 'p.sc-jOiSOi.jgbyVL').text
|
||||||
|
# Zeige eine Nachricht mit der noch zu wartenden Zeit
|
||||||
|
print('Nächster Pot Verfügbar in:', current_time)
|
||||||
|
# Versuche den JWT Token zu extrahieren:
|
||||||
|
WebDriverWait(driver, 10).until(
|
||||||
|
lambda driver: driver.execute_script('return localStorage.getItem("JWT");') is not None)
|
||||||
|
|
||||||
# If the countdown element is present, get the current time and print it
|
# Definiere eine variable mit dem JWT Token inhalt.
|
||||||
current_time = driver.find_element(
|
jwt_token = driver.execute_script('return localStorage.getItem("JWT");')
|
||||||
By.CSS_SELECTOR, 'p.sc-jOiSOi.jgbyVL'
|
|
||||||
).text
|
# Nutze den JWT Token um sich für den API call anzumelden
|
||||||
logger.info("Nächster Pot Verfügbar in: %s", current_time)
|
url = 'https://dashboard.honeygain.com/api/v1/contest_winnings'
|
||||||
|
headers = {'Authorization': f'Bearer {jwt_token}'}
|
||||||
|
response = requests.get(url, headers=headers)
|
||||||
|
# Überprüfe den zurückgegebenen Status Code des API Calls
|
||||||
|
if response.status_code == 200:
|
||||||
|
# Extrahiere die daten aus der json und nenne die variable "winning_credits"
|
||||||
|
winnings = response.json()['data']['winning_credits']
|
||||||
|
# Konvertiere die Credits in $
|
||||||
|
winnings_in_dollars = winnings / 1000
|
||||||
|
# Nun konvertieren wir die Credits in integer und dann zurück in einen String, dadurch streichen wir nachkommastellen (5 Credits werden als 5.0 angegeben, aber es gibt keine 0.5 Credits)
|
||||||
|
winnings_int = int(winnings)
|
||||||
|
winnings_str = str(winnings_int)
|
||||||
|
# Zeige eine Nachricht mit den Credits die heute gewonnen wurden.
|
||||||
|
print('Du hast heute', winnings_str ,'Credits (', winnings_in_dollars, '$) gewonnen.')
|
||||||
|
else:
|
||||||
|
print('Error:', response.status_code, response.text)
|
||||||
except TimeoutException:
|
except TimeoutException:
|
||||||
# If the timer element is not present, click on the lucky pot button
|
# Falls der Timer nicht vorhanden ist, schaue ob der Lucky Port geclaimed werden kann
|
||||||
try:
|
try:
|
||||||
# Wait for the "Open Lucky Pot" button to be present on the page
|
# Warte max 10 Sekunden bis der text "Open Lucky Pot" auf der Seite erscheint.
|
||||||
WebDriverWait(driver, 10).until(EC.presence_of_element_located(
|
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//span[contains(text(), 'Open Lucky Pot')]")))
|
||||||
(By.XPATH, "//span[contains(text(), 'Open Lucky Pot')]"))
|
# Klicke den Lucky Pot button:
|
||||||
)
|
lucky_pot_button = driver.find_element(By.XPATH, "//span[contains(text(), 'Open Lucky Pot')]/ancestor::button")
|
||||||
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()
|
lucky_pot_button.click()
|
||||||
logger.info('Glückwunsch! Ich habe für dich gerade den Lucky Pot geöffnet')
|
# Definiere eine variable mit dem JWT Token inhalt.
|
||||||
|
jwt_token = driver.execute_script('return localStorage.getItem("JWT");')
|
||||||
|
|
||||||
|
# Nutze den JWT Token um sich für den API call anzumelden
|
||||||
|
url = 'https://dashboard.honeygain.com/api/v1/contest_winnings'
|
||||||
|
headers = {'Authorization': f'Bearer {jwt_token}'}
|
||||||
|
response = requests.get(url, headers=headers)
|
||||||
|
# Überprüfe den zurückgegebenen Status Code des API Calls
|
||||||
|
if response.status_code == 200:
|
||||||
|
# Extrahiere die daten aus der json und nenne die variable "winning_credits"
|
||||||
|
winnings = response.json()['data']['winning_credits']
|
||||||
|
# Konvertiere die Credits in $
|
||||||
|
winnings_in_dollars = winnings / 1000
|
||||||
|
# Nun konvertieren wir die Credits in integer und dann zurück in einen String, dadurch streichen wir nachkommastellen (5 Credits werden als 5.0 angegeben, aber es gibt keine 0.5 Credits)
|
||||||
|
winnings_int = int(winnings)
|
||||||
|
winnings_str = str(winnings_int)
|
||||||
|
# Zeige eine Nachricht mit den Credits die heute gewonnen wurden.
|
||||||
|
print('Der LuckyPot wurde erfolgreich geclaimed! Du hast', winnings_str ,'Credits (', winnings_in_dollars, '$) gewonnen.')
|
||||||
|
|
||||||
except TimeoutException:
|
except TimeoutException:
|
||||||
logger.error("The 'Open Lucky Pot' button was not found. Exiting...")
|
print("The 'Open Lucky Pot' button was not found within 10 seconds. 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()
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user