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
3
3
4
4
import logging
5
5
import time
6
6
7
7
# 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' )
9
10
10
- def claim_daily_credits (id : str , email : str , password : str ) -> None :
11
11
12
+ def claim_daily_credits (email : str , password : str ) -> None :
12
13
"""
13
14
Log into the PixAI website and claim the daily credits.
14
15
15
- :param id: The user ID to claim the credits for.
16
16
:param email: The email to login with.
17
17
:param password: The password to login with.
18
18
@@ -33,7 +33,8 @@ def claim_daily_credits(id: str, email: str, password: str) -> None:
33
33
time .sleep (2 )
34
34
35
35
# 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")]' )
37
38
nextbtn .click ()
38
39
39
40
# 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:
43
44
email_input = browser .find_element (By .ID , "email-input" )
44
45
email_input .send_keys (f"{ email } " )
45
46
logging .info ("Credits - Sent email to input field." )
46
- #time.sleep(0.5)
47
+ # time.sleep(0.5)
47
48
48
49
# Find password input field by id and send keys
49
50
password_input = browser .find_element (By .ID , "password-input" )
50
51
password_input .send_keys (f"{ password } " )
51
52
logging .info ("Credits - Sent password to input field." )
52
- #time.sleep(0.5)
53
+ # time.sleep(0.5)
53
54
54
55
# 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")]' )
56
58
login_btn .click ()
57
59
logging .info ("Credits - Clicked login button." )
58
60
59
61
# 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.' )
64
83
65
84
# wait for a bit to let the page load
66
85
time .sleep (2 )
67
86
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')]" )
74
98
except :
75
99
logging .info ("Credits - An Error Occurred." )
76
100
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:
82
106
time .sleep (1 )
83
107
84
108
# Close the browser
85
- browser .quit ()
109
+ browser .quit ()
0 commit comments