XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Fixed entire usesless (huge update)

7e1a0d1f
enganese <b-android@mail.ru>
提交于

代码差异

5 个文件 +195 -24
Modified gpt4free/usesless/README.md +4 -2
@@ -6,9 +6,11 @@ ai.usesless.com
6 6 <p>this will create account.txt that contains mail and token</p>
7 7
8 8 ```python
9 import usesless
9 from gpt4free import usesless
10
10 11
11 usesless.Account.create(logging=True)
12 token = usesless.Account.create(logging=True)
13 print(token)
12 14 ```
13 15
14 16 ### completion
Modified gpt4free/usesless/__init__.py +40 -22
@@ -1,20 +1,32 @@
1 import string
1 2 import time
2 3 import re
3 4 import json
4 5 import requests
5 6 import fake_useragent
6 import names
7
8 from mailgw_temporary_email import Email
7 import random
9 8 from password_generator import PasswordGenerator
10 9
10 from utils import create_email, check_email
11
11 12
12 13 class Account:
13 14 @staticmethod
14 15 def create(logging: bool = False):
15 mail_client = Email()
16 mail_client.register()
17 mail_address = mail_client.address
16 is_custom_domain = input(
17 "Do you want to use your custom domain name for temporary email? [Y/n]: "
18 ).upper()
19
20 if is_custom_domain == "Y":
21 mail_address = create_email(custom_domain=True, logging=logging)
22 elif is_custom_domain == "N":
23 mail_address = create_email(custom_domain=False, logging=logging)
24 else:
25 print("Please, enter either Y or N")
26 return
27
28 name = string.ascii_lowercase + string.digits
29 username = "".join(random.choice(name) for i in range(20))
18 30
19 31 pwo = PasswordGenerator()
20 32 pwo.minlen = 8
@@ -22,12 +34,9 @@ class Account:
22 34
23 35 session = requests.Session()
24 36
25 if logging:
26 print(f"email: {mail_address}")
27
28 37 register_url = "https://ai.usesless.com/api/cms/auth/local/register"
29 38 register_json = {
30 "username": names.get_first_name(),
39 "username": username,
31 40 "password": password,
32 41 "email": mail_address,
33 42 }
@@ -44,23 +53,28 @@ class Account:
44 53 register = session.post(register_url, json=register_json, headers=headers)
45 54 if logging:
46 55 if register.status_code == 200:
47 print("register success")
56 print("Registered successfully")
48 57 else:
49 print("there's a problem with account creation, try again")
58 print(register.status_code)
59 print(register.json())
60 print("There was a problem with account registration, try again")
50 61
51 62 if register.status_code != 200:
52 63 quit()
53 64
54 65 while True:
55 66 time.sleep(5)
56 messages = mail_client.message_list()
67 messages = check_email(mail=mail_address, logging=logging)
68
69 # Check if method `message_list()` didn't return None or empty list.
57 70 if not messages or len(messages) == 0:
71 # If it returned None or empty list sleep for 5 seconds to wait for new message.
58 72 continue
59 message_id = messages[0]["id"]
60 message = mail_client.message(message_id)
73
74 message_text = messages[0]["content"]
61 75 verification_url = re.findall(
62 76 r"http:\/\/ai\.usesless\.com\/api\/cms\/auth\/email-confirmation\?confirmation=\w.+\w\w",
63 message["text"],
77 message_text,
64 78 )[0]
65 79 if verification_url:
66 80 break
@@ -70,13 +84,17 @@ class Account:
70 84 login_request = session.post(
71 85 url="https://ai.usesless.com/api/cms/auth/local", json=login_json
72 86 )
73 token = login_request.json()["jwt"]
74 if logging:
75 print(f"token: {token}")
76 87
77 with open("accounts.txt", "w") as f:
78 f.write(f"{mail_address}\n")
79 f.write(f"{token}")
88 token = login_request.json()["jwt"]
89 if logging and token:
90 print(f"Token: {token}")
91
92 with open("account.json", "w") as file:
93 json.dump({"email": mail_address, "token": token}, file)
94 if logging:
95 print(
96 "\nNew account credentials has been successfully saved in 'account.json' file"
97 )
80 98
81 99 return token
82 100
Added gpt4free/usesless/account.json +1 -0
@@ -0,0 +1 @@
1 {"email": "enganese-test-email@1secmail.net", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Mzg1MDEsImlhdCI6MTY4NTExMDgzOSwiZXhwIjoxNzE2NjY4NDM5fQ.jfEQOFWYQP2Xx4U-toorPg3nh31mxl3L0D2hRROmjZA"}
Added gpt4free/usesless/test.py +10 -0
@@ -0,0 +1,10 @@
1 # Fix by @enganese
2 # Import Account class from __init__.py file
3 from gpt4free import usesless
4
5 # Create Account and enable logging to see all the log messages (it's very interesting, try it!)
6 # New account credentials will be automatically saved in account.json file in such template: {"email": "username@1secmail.com", "token": "token here"}
7 token = usesless.Account.create(logging=True)
8
9 # Print the new token
10 print(token)
Added gpt4free/usesless/utils/__init__.py +140 -0
@@ -0,0 +1,140 @@
1 import pyperclip
2 import requests
3 import random
4 import string
5 import time
6 import sys
7 import re
8 import os
9
10
11 def check_email(mail, logging: bool = False):
12 username = mail.split("@")[0]
13 domain = mail.split("@")[1]
14 reqLink = f"https://www.1secmail.com/api/v1/?action=getMessages&login={username}&domain={domain}"
15 req = requests.get(reqLink)
16 req.encoding = req.apparent_encoding
17 req = req.json()
18
19 length = len(req)
20
21 if logging:
22 os.system("cls" if os.name == "nt" else "clear")
23 time.sleep(1)
24 print("Your temporary mail:", mail)
25
26 if logging and length == 0:
27 print(
28 "Mailbox is empty. Hold tight. Mailbox is refreshed automatically every 5 seconds.",
29 )
30 else:
31 messages = []
32 id_list = []
33
34 for i in req:
35 for k, v in i.items():
36 if k == "id":
37 id_list.append(v)
38
39 x = "mails" if length > 1 else "mail"
40
41 if logging:
42 print(
43 f"Mailbox has {length} {x}. (Mailbox is refreshed automatically every 5 seconds.)"
44 )
45
46 for i in id_list:
47 msgRead = f"https://www.1secmail.com/api/v1/?action=readMessage&login={username}&domain={domain}&id={i}"
48 req = requests.get(msgRead)
49 req.encoding = req.apparent_encoding
50 req = req.json()
51
52 for k, v in req.items():
53 if k == "from":
54 sender = v
55 if k == "subject":
56 subject = v
57 if k == "date":
58 date = v
59 if k == "textBody":
60 content = v
61
62 if logging:
63 print(
64 "Sender:",
65 sender,
66 "\nTo:",
67 mail,
68 "\nSubject:",
69 subject,
70 "\nDate:",
71 date,
72 "\nContent:",
73 content,
74 "\n",
75 )
76 messages.append(
77 {
78 "sender": sender,
79 "to": mail,
80 "subject": subject,
81 "date": date,
82 "content": content,
83 }
84 )
85
86 if logging:
87 os.system("cls" if os.name == "nt" else "clear")
88 return messages
89
90
91 def create_email(custom_domain: bool = False, logging: bool = False):
92 domainList = ["1secmail.com", "1secmail.net", "1secmail.org"]
93 domain = random.choice(domainList)
94 try:
95 if custom_domain:
96 custom_domain = input(
97 "\nIf you enter 'my-test-email' as your domain name, mail address will look like this: 'my-test-email@1secmail.com'"
98 "\nEnter the name that you wish to use as your domain name: "
99 )
100
101 newMail = f"https://www.1secmail.com/api/v1/?login={custom_domain}&domain={domain}"
102 reqMail = requests.get(newMail)
103 reqMail.encoding = reqMail.apparent_encoding
104
105 username = re.search(r"login=(.*)&", newMail).group(1)
106 domain = re.search(r"domain=(.*)", newMail).group(1)
107 mail = f"{username}@{domain}"
108
109 if logging:
110 print("\nYour temporary email was created successfully:", mail)
111 return mail
112
113 else:
114 name = string.ascii_lowercase + string.digits
115 random_username = "".join(random.choice(name) for i in range(10))
116 newMail = f"https://www.1secmail.com/api/v1/?login={random_username}&domain={domain}"
117
118 reqMail = requests.get(newMail)
119 reqMail.encoding = reqMail.apparent_encoding
120
121 username = re.search(r"login=(.*)&", newMail).group(1)
122 domain = re.search(r"domain=(.*)", newMail).group(1)
123 mail = f"{username}@{domain}"
124
125 if logging:
126 print("\nYour temporary email was created successfully:", mail)
127 return mail
128
129 except KeyboardInterrupt:
130 requests.post(
131 "https://www.1secmail.com/mailbox",
132 data={
133 "action": "deleteMailbox",
134 "login": f"{username}",
135 "domain": f"{domain}",
136 },
137 )
138 if logging:
139 print("\nKeyboard Interrupt Detected! \nTemporary mail was disposed!")
140 os.system("cls" if os.name == "nt" else "clear")