Skip to content

Commit

Permalink
Merge pull request #2 from MahdeenSky/fixed_claim_credits
Browse files Browse the repository at this point in the history
Updated README, fixed and removed redundant code about claim_credits.py
  • Loading branch information
5eroo authored Apr 4, 2024
2 parents 440044e + 1cbff21 commit 48e167f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 45 deletions.
27 changes: 2 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,39 +203,16 @@ Output:

### Auto-claiming your daily credits

To auto-claim your daily credits, first import the code to claim credits and the code to get your jwt
To auto-claim your daily credits, first import the code to claim credits

```py
from res.scripts.claim_credits import claim_daily_credits
from res.scripts.get_jwt import get_jwt
```

Next, import the function for retrieving the user id

```py
from res.scripts.user_id import get_user_id
```

Then, retrieve your jwt

```py
__jwt: str = get_jwt(
email="xxxxxx", # your email here
password="xxxxxx" # your password here
)
```

Afterwards, get your user ID:

```py
user_id = get_user_id(__jwt)
```

Lastly, call the `claim_daily_credits` function
Then, call the `claim_daily_credits` function

```py
claim_daily_credits(
id=user_id,
email="xxxxxxx", # your email here
password="xxxxxx" # your password here
)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
requests
fake_useragent
pillow
selenium
64 changes: 44 additions & 20 deletions res/scripts/claim_credits.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.common.by import By

import logging
import time

# logging configuration
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s')

def claim_daily_credits(id: str, email: str, password: str) -> None:

def claim_daily_credits(email: str, password: str) -> None:
"""
Log into the PixAI website and claim the daily credits.
:param id: The user ID to claim the credits for.
:param email: The email to login with.
:param password: The password to login with.
Expand All @@ -33,7 +33,8 @@ def claim_daily_credits(id: str, email: str, password: str) -> None:
time.sleep(2)

# Click button with specific text
nextbtn = browser.find_element(By.XPATH, '//button[contains(text(), "Log in with email")]')
nextbtn = browser.find_element(
By.XPATH, '//button[contains(text(), "Log in with email")]')
nextbtn.click()

# Wait for a bit to let the next page load
Expand All @@ -43,34 +44,57 @@ def claim_daily_credits(id: str, email: str, password: str) -> None:
email_input = browser.find_element(By.ID, "email-input")
email_input.send_keys(f"{email}")
logging.info("Credits - Sent email to input field.")
#time.sleep(0.5)
# time.sleep(0.5)

# Find password input field by id and send keys
password_input = browser.find_element(By.ID, "password-input")
password_input.send_keys(f"{password}")
logging.info("Credits - Sent password to input field.")
#time.sleep(0.5)
# time.sleep(0.5)

# Find login button by id and click
login_btn = browser.find_element(By.XPATH, '//button[contains(text(), "Login")]')
login_btn = browser.find_element(
By.XPATH, '//button[contains(text(), "Login")]')
login_btn.click()
logging.info("Credits - Clicked login button.")

# wait for a bit to let the page load
time.sleep(2)

# go to new site
browser.get(f"https://pixai.art/@user-{id}/artworks")
time.sleep(5)

# click two buttons to get to the profile page with the claim button
try:
# get the last child of header element and click it
print("Trying to find profile icon button.")
profileIcon_btn = browser.find_element(
By.XPATH, "//header/*[last()]")
print("Found profile icon button.")
profileIcon_btn.click()
time.sleep(2)

# click the span element with the text "Profile"
print("Trying to find profile button.")
profile_btn = browser.find_element(
By.XPATH, "//span[contains(text(), 'Profile')]")
print("Found profile button.")
profile_btn.click()
except:
logging.info("Credits - An Error Occurred.")
quit('An Error Occurred: Could not find profile icon button or profile button.')

# wait for a bit to let the page load
time.sleep(2)

# find button with specific class
try: claim_btn = browser.find_element(By.XPATH, "//button[contains(span/text(), 'Claim')]")
except:

# try finding claimed text instead
try: claim_btn = browser.find_element(By.XPATH, "//button[contains(span/text(), 'Claimed')]"); logging.info("Credits - Already claimed."); return
try:
# Check if the credits have already been claimed
claim_btn = browser.find_element(
By.XPATH, "//button[contains(span/text(), 'Claimed')]")
logging.info("Credits - Already claimed.")
return
except:
# If not claimed then find the claim button
try:
claim_btn = browser.find_element(
By.XPATH, "//button[contains(span/text(), 'Claim')]")
except:
logging.info("Credits - An Error Occurred.")
quit('An Error Occurred: Could not find "Claimed" or "Claim" button.')
Expand All @@ -82,4 +106,4 @@ def claim_daily_credits(id: str, email: str, password: str) -> None:
time.sleep(1)

# Close the browser
browser.quit()
browser.quit()

0 comments on commit 48e167f

Please sign in to comment.