-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
executable file
·123 lines (107 loc) · 3.83 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/python3
__version__ = "1.0.0"
__author__ = "Smartwa Caleb"
class handler:
def __init__(self):
pass
def get_args(self):
import argparse
parser = argparse.ArgumentParser(description="Automate GPT3 login-process")
parser.add_argument(
"-v", "--version", action="version", version=f"%(prog)s v{__version__}"
)
parser.add_argument("email", help="Google mail-address")
parser.add_argument("password", help="Passphrase for the account")
parser.add_argument("-d", "--driver", help="Absolute path to chromedriver")
parser.add_argument(
"-se",
"--session",
help="Total session time in minutes",
type=int,
default=30,
)
parser.add_argument(
"--incognito", help="Run browser in incognito mode", action="store_true"
)
return parser.parse_args()
def log(self):
import logging
logging.basicConfig(
format="%(asctime)s - %(levelname)s : %(message)s",
datefmt="%d-%b-%Y %H:%M:%S",
level=logging.INFO,
)
return logging
def main(self):
return self.get_args(), self.log()
args, logging = handler().main()
import undetected_chromedriver as webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from time import sleep as wait
from sys import exit
class gpt3:
def __init__(self):
options = webdriver.ChromeOptions()
for val in [
"--start-maximized",
"--incognito" if args.incognito else None,
]:
if val:
options.add_argument(val)
args_to_be_passed = {
"options": options,
}
if args.driver:
args_to_be_passed["driver_executable_path"] = args.driver
self.get_error = lambda err: str(err).split("\n")[0]
self.driver = webdriver.Chrome(**args_to_be_passed)
def login(self, email: str, password: str):
"""Controls the login process.
:param email: Your google e-mail account address
:param password: E-mail address passphrase.
"""
try:
self.driver.get("https://platform.openai.com/playground")
self.driver.find_element(By.CLASS_NAME, "btn-label-inner").click()
self.driver.find_element(
By.XPATH, '//button[@data-provider="google"]'
).click()
self.enter_email(email)
wait(2)
self.enter_password(password)
except Exception as e:
exit(logging.error(self.get_error(e)))
def enter_email(self, email: str):
try:
email_elm = self.driver.find_element(By.XPATH, '//input[@type="email"]')
email_elm.send_keys(email)
email_elm.send_keys(Keys.ENTER)
except Exception as e:
exit(logging.error(self.get_error(e)))
def enter_password(self, password: str):
logging.debug("Keying-in password")
try:
password_elm = self.driver.find_element(
By.XPATH, '//input[@type="password"]'
)
password_elm.click()
password_elm.send_keys(password)
password_elm.send_keys(Keys.ENTER)
self.driver.implicitly_wait(2)
except Exception as e:
exit(logging.error(self.get_error(e)))
else:
logging.info("Login successfully")
if __name__ == "__main__":
logging.info("GPT3 Started")
start = gpt3()
try:
start.login(email=args.email, password=args.password)
wait(args.session * 60)
except (KeyboardInterrupt, EOFError):
exit(logging.info("Stopping program!"))
except Exception as e:
logging.critical(start.get_error(e))
finally:
start.driver.quit()