Skip to content

Commit 48e167f

Browse files
authored
Merge pull request #2 from MahdeenSky/fixed_claim_credits
Updated README, fixed and removed redundant code about claim_credits.py
2 parents 440044e + 1cbff21 commit 48e167f

File tree

3 files changed

+47
-45
lines changed

3 files changed

+47
-45
lines changed

README.md

+2-25
Original file line numberDiff line numberDiff line change
@@ -203,39 +203,16 @@ Output:
203203

204204
### Auto-claiming your daily credits
205205

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

208208
```py
209209
from res.scripts.claim_credits import claim_daily_credits
210-
from res.scripts.get_jwt import get_jwt
211-
```
212-
213-
Next, import the function for retrieving the user id
214-
215-
```py
216-
from res.scripts.user_id import get_user_id
217-
```
218-
219-
Then, retrieve your jwt
220-
221-
```py
222-
__jwt: str = get_jwt(
223-
email="xxxxxx", # your email here
224-
password="xxxxxx" # your password here
225-
)
226-
```
227-
228-
Afterwards, get your user ID:
229-
230-
```py
231-
user_id = get_user_id(__jwt)
232210
```
233211

234-
Lastly, call the `claim_daily_credits` function
212+
Then, call the `claim_daily_credits` function
235213

236214
```py
237215
claim_daily_credits(
238-
id=user_id,
239216
email="xxxxxxx", # your email here
240217
password="xxxxxx" # your password here
241218
)

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
requests
22
fake_useragent
33
pillow
4+
selenium

res/scripts/claim_credits.py

+44-20
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
from selenium import webdriver
2-
from selenium.webdriver.common.by import By
1+
from selenium import webdriver
2+
from selenium.webdriver.common.by import By
33

44
import logging
55
import time
66

77
# logging configuration
8-
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
8+
logging.basicConfig(level=logging.INFO,
9+
format='%(asctime)s - %(levelname)s - %(message)s')
910

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

12+
def claim_daily_credits(email: str, password: str) -> None:
1213
"""
1314
Log into the PixAI website and claim the daily credits.
1415
15-
:param id: The user ID to claim the credits for.
1616
:param email: The email to login with.
1717
:param password: The password to login with.
1818
@@ -33,7 +33,8 @@ def claim_daily_credits(id: str, email: str, password: str) -> None:
3333
time.sleep(2)
3434

3535
# Click button with specific text
36-
nextbtn = browser.find_element(By.XPATH, '//button[contains(text(), "Log in with email")]')
36+
nextbtn = browser.find_element(
37+
By.XPATH, '//button[contains(text(), "Log in with email")]')
3738
nextbtn.click()
3839

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

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

5455
# Find login button by id and click
55-
login_btn = browser.find_element(By.XPATH, '//button[contains(text(), "Login")]')
56+
login_btn = browser.find_element(
57+
By.XPATH, '//button[contains(text(), "Login")]')
5658
login_btn.click()
5759
logging.info("Credits - Clicked login button.")
5860

5961
# wait for a bit to let the page load
60-
time.sleep(2)
61-
62-
# go to new site
63-
browser.get(f"https://pixai.art/@user-{id}/artworks")
62+
time.sleep(5)
63+
64+
# click two buttons to get to the profile page with the claim button
65+
try:
66+
# get the last child of header element and click it
67+
print("Trying to find profile icon button.")
68+
profileIcon_btn = browser.find_element(
69+
By.XPATH, "//header/*[last()]")
70+
print("Found profile icon button.")
71+
profileIcon_btn.click()
72+
time.sleep(2)
73+
74+
# click the span element with the text "Profile"
75+
print("Trying to find profile button.")
76+
profile_btn = browser.find_element(
77+
By.XPATH, "//span[contains(text(), 'Profile')]")
78+
print("Found profile button.")
79+
profile_btn.click()
80+
except:
81+
logging.info("Credits - An Error Occurred.")
82+
quit('An Error Occurred: Could not find profile icon button or profile button.')
6483

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

68-
# find button with specific class
69-
try: claim_btn = browser.find_element(By.XPATH, "//button[contains(span/text(), 'Claim')]")
70-
except:
71-
72-
# try finding claimed text instead
73-
try: claim_btn = browser.find_element(By.XPATH, "//button[contains(span/text(), 'Claimed')]"); logging.info("Credits - Already claimed."); return
87+
try:
88+
# Check if the credits have already been claimed
89+
claim_btn = browser.find_element(
90+
By.XPATH, "//button[contains(span/text(), 'Claimed')]")
91+
logging.info("Credits - Already claimed.")
92+
return
93+
except:
94+
# If not claimed then find the claim button
95+
try:
96+
claim_btn = browser.find_element(
97+
By.XPATH, "//button[contains(span/text(), 'Claim')]")
7498
except:
7599
logging.info("Credits - An Error Occurred.")
76100
quit('An Error Occurred: Could not find "Claimed" or "Claim" button.')
@@ -82,4 +106,4 @@ def claim_daily_credits(id: str, email: str, password: str) -> None:
82106
time.sleep(1)
83107

84108
# Close the browser
85-
browser.quit()
109+
browser.quit()

0 commit comments

Comments
 (0)