diff options
Diffstat (limited to 'gpt4free')
-rw-r--r-- | gpt4free/usesless/README.md | 14 | ||||
-rw-r--r-- | gpt4free/usesless/__init__.py | 62 | ||||
-rw-r--r-- | gpt4free/usesless/account.json | 1 | ||||
-rw-r--r-- | gpt4free/usesless/test.py | 10 | ||||
-rw-r--r-- | gpt4free/usesless/utils/__init__.py | 139 |
5 files changed, 198 insertions, 28 deletions
diff --git a/gpt4free/usesless/README.md b/gpt4free/usesless/README.md index 426314cb..7b2ea169 100644 --- a/gpt4free/usesless/README.md +++ b/gpt4free/usesless/README.md @@ -2,17 +2,19 @@ ai.usesless.com ### Example: `usesless` <a name="example-usesless"></a> -### token generation -<p>this will create account.txt that contains mail and token</p> +### Token generation +<p>This will create account.json that contains email and token in json</p> ```python -import usesless +from gpt4free import usesless + -usesless.Account.create(logging=True) +token = usesless.Account.create(logging=True) +print(token) ``` -### completion -<p>insert token from account.txt</p> +### Completion +<p>Insert token from account.json</p> ```python import usesless diff --git a/gpt4free/usesless/__init__.py b/gpt4free/usesless/__init__.py index 1192192e..f8b6a78e 100644 --- a/gpt4free/usesless/__init__.py +++ b/gpt4free/usesless/__init__.py @@ -1,20 +1,32 @@ +import string import time import re import json import requests import fake_useragent -import names - -from mailgw_temporary_email import Email +import random from password_generator import PasswordGenerator +from utils import create_email, check_email + class Account: @staticmethod def create(logging: bool = False): - mail_client = Email() - mail_client.register() - mail_address = mail_client.address + is_custom_domain = input( + "Do you want to use your custom domain name for temporary email? [Y/n]: " + ).upper() + + if is_custom_domain == "Y": + mail_address = create_email(custom_domain=True, logging=logging) + elif is_custom_domain == "N": + mail_address = create_email(custom_domain=False, logging=logging) + else: + print("Please, enter either Y or N") + return + + name = string.ascii_lowercase + string.digits + username = "".join(random.choice(name) for i in range(20)) pwo = PasswordGenerator() pwo.minlen = 8 @@ -22,12 +34,9 @@ class Account: session = requests.Session() - if logging: - print(f"email: {mail_address}") - register_url = "https://ai.usesless.com/api/cms/auth/local/register" register_json = { - "username": names.get_first_name(), + "username": username, "password": password, "email": mail_address, } @@ -44,23 +53,28 @@ class Account: register = session.post(register_url, json=register_json, headers=headers) if logging: if register.status_code == 200: - print("register success") + print("Registered successfully") else: - print("there's a problem with account creation, try again") + print(register.status_code) + print(register.json()) + print("There was a problem with account registration, try again") if register.status_code != 200: quit() while True: time.sleep(5) - messages = mail_client.message_list() + messages = check_email(mail=mail_address, logging=logging) + + # Check if method `message_list()` didn't return None or empty list. if not messages or len(messages) == 0: + # If it returned None or empty list sleep for 5 seconds to wait for new message. continue - message_id = messages[0]["id"] - message = mail_client.message(message_id) + + message_text = messages[0]["content"] verification_url = re.findall( r"http:\/\/ai\.usesless\.com\/api\/cms\/auth\/email-confirmation\?confirmation=\w.+\w\w", - message["text"], + message_text, )[0] if verification_url: break @@ -70,13 +84,17 @@ class Account: login_request = session.post( url="https://ai.usesless.com/api/cms/auth/local", json=login_json ) - token = login_request.json()["jwt"] - if logging: - print(f"token: {token}") - with open("accounts.txt", "w") as f: - f.write(f"{mail_address}\n") - f.write(f"{token}") + token = login_request.json()["jwt"] + if logging and token: + print(f"Token: {token}") + + with open("account.json", "w") as file: + json.dump({"email": mail_address, "token": token}, file) + if logging: + print( + "\nNew account credentials has been successfully saved in 'account.json' file" + ) return token diff --git a/gpt4free/usesless/account.json b/gpt4free/usesless/account.json new file mode 100644 index 00000000..53a210ac --- /dev/null +++ b/gpt4free/usesless/account.json @@ -0,0 +1 @@ +{"email": "enganese-test-email@1secmail.net", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Mzg1MDEsImlhdCI6MTY4NTExMDgzOSwiZXhwIjoxNzE2NjY4NDM5fQ.jfEQOFWYQP2Xx4U-toorPg3nh31mxl3L0D2hRROmjZA"}
\ No newline at end of file diff --git a/gpt4free/usesless/test.py b/gpt4free/usesless/test.py new file mode 100644 index 00000000..ade1e0c5 --- /dev/null +++ b/gpt4free/usesless/test.py @@ -0,0 +1,10 @@ +# Fix by @enganese +# Import Account class from __init__.py file +from gpt4free import usesless + +# Create Account and enable logging to see all the log messages (it's very interesting, try it!) +# New account credentials will be automatically saved in account.json file in such template: {"email": "username@1secmail.com", "token": "token here"} +token = usesless.Account.create(logging=True) + +# Print the new token +print(token) diff --git a/gpt4free/usesless/utils/__init__.py b/gpt4free/usesless/utils/__init__.py new file mode 100644 index 00000000..818c605d --- /dev/null +++ b/gpt4free/usesless/utils/__init__.py @@ -0,0 +1,139 @@ +import requests +import random +import string +import time +import sys +import re +import os + + +def check_email(mail, logging: bool = False): + username = mail.split("@")[0] + domain = mail.split("@")[1] + reqLink = f"https://www.1secmail.com/api/v1/?action=getMessages&login={username}&domain={domain}" + req = requests.get(reqLink) + req.encoding = req.apparent_encoding + req = req.json() + + length = len(req) + + if logging: + os.system("cls" if os.name == "nt" else "clear") + time.sleep(1) + print("Your temporary mail:", mail) + + if logging and length == 0: + print( + "Mailbox is empty. Hold tight. Mailbox is refreshed automatically every 5 seconds.", + ) + else: + messages = [] + id_list = [] + + for i in req: + for k, v in i.items(): + if k == "id": + id_list.append(v) + + x = "mails" if length > 1 else "mail" + + if logging: + print( + f"Mailbox has {length} {x}. (Mailbox is refreshed automatically every 5 seconds.)" + ) + + for i in id_list: + msgRead = f"https://www.1secmail.com/api/v1/?action=readMessage&login={username}&domain={domain}&id={i}" + req = requests.get(msgRead) + req.encoding = req.apparent_encoding + req = req.json() + + for k, v in req.items(): + if k == "from": + sender = v + if k == "subject": + subject = v + if k == "date": + date = v + if k == "textBody": + content = v + + if logging: + print( + "Sender:", + sender, + "\nTo:", + mail, + "\nSubject:", + subject, + "\nDate:", + date, + "\nContent:", + content, + "\n", + ) + messages.append( + { + "sender": sender, + "to": mail, + "subject": subject, + "date": date, + "content": content, + } + ) + + if logging: + os.system("cls" if os.name == "nt" else "clear") + return messages + + +def create_email(custom_domain: bool = False, logging: bool = False): + domainList = ["1secmail.com", "1secmail.net", "1secmail.org"] + domain = random.choice(domainList) + try: + if custom_domain: + custom_domain = input( + "\nIf you enter 'my-test-email' as your domain name, mail address will look like this: 'my-test-email@1secmail.com'" + "\nEnter the name that you wish to use as your domain name: " + ) + + newMail = f"https://www.1secmail.com/api/v1/?login={custom_domain}&domain={domain}" + reqMail = requests.get(newMail) + reqMail.encoding = reqMail.apparent_encoding + + username = re.search(r"login=(.*)&", newMail).group(1) + domain = re.search(r"domain=(.*)", newMail).group(1) + mail = f"{username}@{domain}" + + if logging: + print("\nYour temporary email was created successfully:", mail) + return mail + + else: + name = string.ascii_lowercase + string.digits + random_username = "".join(random.choice(name) for i in range(10)) + newMail = f"https://www.1secmail.com/api/v1/?login={random_username}&domain={domain}" + + reqMail = requests.get(newMail) + reqMail.encoding = reqMail.apparent_encoding + + username = re.search(r"login=(.*)&", newMail).group(1) + domain = re.search(r"domain=(.*)", newMail).group(1) + mail = f"{username}@{domain}" + + if logging: + print("\nYour temporary email was created successfully:", mail) + return mail + + except KeyboardInterrupt: + requests.post( + "https://www.1secmail.com/mailbox", + data={ + "action": "deleteMailbox", + "login": f"{username}", + "domain": f"{domain}", + }, + ) + if logging: + print("\nKeyboard Interrupt Detected! \nTemporary mail was disposed!") + os.system("cls" if os.name == "nt" else "clear") |