Spaces:
Paused
Paused
Upload register_bot.py
Browse files- register_bot.py +88 -57
register_bot.py
CHANGED
|
@@ -18,7 +18,7 @@ import logging
|
|
| 18 |
|
| 19 |
# 配置日志(仅控制台输出)
|
| 20 |
logging.basicConfig(
|
| 21 |
-
level=logging.
|
| 22 |
format='%(asctime)s - %(levelname)s - %(message)s',
|
| 23 |
stream=sys.stdout
|
| 24 |
)
|
|
@@ -63,9 +63,11 @@ def get_temp_email():
|
|
| 63 |
try:
|
| 64 |
response = session.get(TEMP_EMAIL_API)
|
| 65 |
if response.status_code == 200:
|
| 66 |
-
|
|
|
|
|
|
|
| 67 |
except requests.exceptions.SSLError as e:
|
| 68 |
-
logging.error(f"SSL Error: {e}")
|
| 69 |
return None
|
| 70 |
|
| 71 |
def register(email, password):
|
|
@@ -92,8 +94,11 @@ def register(email, password):
|
|
| 92 |
try:
|
| 93 |
response = session.post(REGISTER_API_URL, headers=headers, json=payload)
|
| 94 |
|
|
|
|
|
|
|
|
|
|
| 95 |
if response.status_code == 200:
|
| 96 |
-
logging.info(f"Registered with email: {email}")
|
| 97 |
return True
|
| 98 |
elif response.status_code == 429:
|
| 99 |
logging.warning(f"Rate limit reached. Waiting {RATE_LIMIT_DELAY} seconds.")
|
|
@@ -103,20 +108,18 @@ def register(email, password):
|
|
| 103 |
return False
|
| 104 |
|
| 105 |
except requests.exceptions.RequestException as e:
|
| 106 |
-
logging.error(f"Request error: {e}")
|
| 107 |
if attempt < MAX_RETRIES - 1:
|
| 108 |
-
logging.info(f"Retrying in {RETRY_DELAY} seconds...")
|
| 109 |
time.sleep(RETRY_DELAY)
|
| 110 |
else:
|
| 111 |
-
logging.error("Max retries reached.")
|
| 112 |
return False
|
| 113 |
|
| 114 |
return False
|
| 115 |
|
| 116 |
def save_account(email, password):
|
| 117 |
-
# 上传到指定 URL
|
| 118 |
try:
|
| 119 |
-
# 先获取现有内容
|
| 120 |
session = requests.Session()
|
| 121 |
|
| 122 |
# 首先进行认证
|
|
@@ -129,11 +132,15 @@ def save_account(email, password):
|
|
| 129 |
}
|
| 130 |
|
| 131 |
# 获取现有内容
|
|
|
|
| 132 |
response = session.get(auth_url, headers=auth_headers)
|
| 133 |
|
|
|
|
|
|
|
|
|
|
| 134 |
if response.status_code != 200:
|
| 135 |
-
logging.error(f"
|
| 136 |
-
return
|
| 137 |
|
| 138 |
# 从响应获取现有内容
|
| 139 |
existing_data = response.json()
|
|
@@ -145,6 +152,8 @@ def save_account(email, password):
|
|
| 145 |
else:
|
| 146 |
new_content = f"{email}|{password}"
|
| 147 |
|
|
|
|
|
|
|
| 148 |
# 上传新内容
|
| 149 |
upload_headers = {
|
| 150 |
'Authorization': 'Basic emhvdWRhbjp6aG91ZGFu',
|
|
@@ -155,15 +164,22 @@ def save_account(email, password):
|
|
| 155 |
'content': new_content
|
| 156 |
}
|
| 157 |
|
|
|
|
| 158 |
upload_response = session.put(UPLOAD_URL, headers=upload_headers, json=upload_payload)
|
| 159 |
|
|
|
|
|
|
|
|
|
|
| 160 |
if upload_response.status_code == 200:
|
| 161 |
logging.info(f"Successfully uploaded account {email}")
|
|
|
|
| 162 |
else:
|
| 163 |
logging.error(f"Failed to upload account {email}. Status code: {upload_response.status_code}")
|
|
|
|
| 164 |
|
| 165 |
except Exception as e:
|
| 166 |
-
logging.error(f"
|
|
|
|
| 167 |
|
| 168 |
def check_email(email):
|
| 169 |
domain = email.split('@')[1]
|
|
@@ -176,56 +192,66 @@ def check_email(email):
|
|
| 176 |
retries = Retry(total=5, backoff_factor=1, status_forcelist=[500, 502, 503, 504])
|
| 177 |
session.mount('https://', HTTPAdapter(max_retries=retries))
|
| 178 |
|
|
|
|
|
|
|
| 179 |
time.sleep(10)
|
| 180 |
|
| 181 |
for _ in range(20):
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
logging.info(f"Full message content: {full_message}")
|
| 193 |
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
verification_link = match.group(0)
|
| 198 |
-
logging.info(f"Verification link found: {verification_link}")
|
| 199 |
|
| 200 |
-
#
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
else:
|
| 223 |
-
logging.error(f"Failed to
|
| 224 |
return False
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
logging.warning(f"No verification email found for {email}")
|
| 230 |
return False
|
| 231 |
|
|
@@ -252,8 +278,13 @@ def process_account(email):
|
|
| 252 |
password = generate_strong_password()
|
| 253 |
|
| 254 |
if register(email, password):
|
| 255 |
-
save_account(email, password)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
if check_email(email):
|
|
|
|
| 257 |
return {'email': email, 'password': password}
|
| 258 |
except Exception as e:
|
| 259 |
logging.error(f"Error processing account {email}: {e}")
|
|
@@ -263,7 +294,7 @@ def main():
|
|
| 263 |
num_accounts = 5 # 可以根据需要修改注册数量
|
| 264 |
successful_accounts = register_and_verify(num_accounts)
|
| 265 |
|
| 266 |
-
#
|
| 267 |
print(f"Successfully registered {len(successful_accounts)} accounts")
|
| 268 |
for account in successful_accounts:
|
| 269 |
print(f"Email: {account['email']}, Password: {account['password']}")
|
|
|
|
| 18 |
|
| 19 |
# 配置日志(仅控制台输出)
|
| 20 |
logging.basicConfig(
|
| 21 |
+
level=logging.DEBUG, # 改为DEBUG级别,获取更详细的日志
|
| 22 |
format='%(asctime)s - %(levelname)s - %(message)s',
|
| 23 |
stream=sys.stdout
|
| 24 |
)
|
|
|
|
| 63 |
try:
|
| 64 |
response = session.get(TEMP_EMAIL_API)
|
| 65 |
if response.status_code == 200:
|
| 66 |
+
email = response.json()[0]
|
| 67 |
+
logging.info(f"Generated temp email: {email}")
|
| 68 |
+
return email
|
| 69 |
except requests.exceptions.SSLError as e:
|
| 70 |
+
logging.error(f"SSL Error getting temp email: {e}")
|
| 71 |
return None
|
| 72 |
|
| 73 |
def register(email, password):
|
|
|
|
| 94 |
try:
|
| 95 |
response = session.post(REGISTER_API_URL, headers=headers, json=payload)
|
| 96 |
|
| 97 |
+
logging.info(f"Registration response status: {response.status_code}")
|
| 98 |
+
logging.info(f"Registration response content: {response.text}")
|
| 99 |
+
|
| 100 |
if response.status_code == 200:
|
| 101 |
+
logging.info(f"Registered successfully with email: {email}")
|
| 102 |
return True
|
| 103 |
elif response.status_code == 429:
|
| 104 |
logging.warning(f"Rate limit reached. Waiting {RATE_LIMIT_DELAY} seconds.")
|
|
|
|
| 108 |
return False
|
| 109 |
|
| 110 |
except requests.exceptions.RequestException as e:
|
| 111 |
+
logging.error(f"Request error during registration: {e}")
|
| 112 |
if attempt < MAX_RETRIES - 1:
|
| 113 |
+
logging.info(f"Retrying registration in {RETRY_DELAY} seconds...")
|
| 114 |
time.sleep(RETRY_DELAY)
|
| 115 |
else:
|
| 116 |
+
logging.error("Max registration retries reached.")
|
| 117 |
return False
|
| 118 |
|
| 119 |
return False
|
| 120 |
|
| 121 |
def save_account(email, password):
|
|
|
|
| 122 |
try:
|
|
|
|
| 123 |
session = requests.Session()
|
| 124 |
|
| 125 |
# 首先进行认证
|
|
|
|
| 132 |
}
|
| 133 |
|
| 134 |
# 获取现有内容
|
| 135 |
+
logging.info(f"Authenticating with URL: {auth_url}")
|
| 136 |
response = session.get(auth_url, headers=auth_headers)
|
| 137 |
|
| 138 |
+
logging.info(f"Authentication response status: {response.status_code}")
|
| 139 |
+
logging.info(f"Authentication response content: {response.text}")
|
| 140 |
+
|
| 141 |
if response.status_code != 200:
|
| 142 |
+
logging.error(f"Authentication failed, status code: {response.status_code}")
|
| 143 |
+
return False
|
| 144 |
|
| 145 |
# 从响应获取现有内容
|
| 146 |
existing_data = response.json()
|
|
|
|
| 152 |
else:
|
| 153 |
new_content = f"{email}|{password}"
|
| 154 |
|
| 155 |
+
logging.info(f"New content to upload: {new_content}")
|
| 156 |
+
|
| 157 |
# 上传新内容
|
| 158 |
upload_headers = {
|
| 159 |
'Authorization': 'Basic emhvdWRhbjp6aG91ZGFu',
|
|
|
|
| 164 |
'content': new_content
|
| 165 |
}
|
| 166 |
|
| 167 |
+
logging.info(f"Uploading to URL: {UPLOAD_URL}")
|
| 168 |
upload_response = session.put(UPLOAD_URL, headers=upload_headers, json=upload_payload)
|
| 169 |
|
| 170 |
+
logging.info(f"Upload response status: {upload_response.status_code}")
|
| 171 |
+
logging.info(f"Upload response content: {upload_response.text}")
|
| 172 |
+
|
| 173 |
if upload_response.status_code == 200:
|
| 174 |
logging.info(f"Successfully uploaded account {email}")
|
| 175 |
+
return True
|
| 176 |
else:
|
| 177 |
logging.error(f"Failed to upload account {email}. Status code: {upload_response.status_code}")
|
| 178 |
+
return False
|
| 179 |
|
| 180 |
except Exception as e:
|
| 181 |
+
logging.error(f"Comprehensive error uploading account: {e}")
|
| 182 |
+
return False
|
| 183 |
|
| 184 |
def check_email(email):
|
| 185 |
domain = email.split('@')[1]
|
|
|
|
| 192 |
retries = Retry(total=5, backoff_factor=1, status_forcelist=[500, 502, 503, 504])
|
| 193 |
session.mount('https://', HTTPAdapter(max_retries=retries))
|
| 194 |
|
| 195 |
+
logging.info(f"Checking email for {email}")
|
| 196 |
+
|
| 197 |
time.sleep(10)
|
| 198 |
|
| 199 |
for _ in range(20):
|
| 200 |
+
try:
|
| 201 |
+
response = session.get(mailbox_url)
|
| 202 |
+
logging.info(f"Email check response status: {response.status_code}")
|
| 203 |
+
|
| 204 |
+
if response.status_code == 200 and response.json():
|
| 205 |
+
for message in response.json():
|
| 206 |
+
if "Confirm Your Signup" in message.get('subject', ''):
|
| 207 |
+
# 获取完整邮件内容
|
| 208 |
+
message_url = f"https://www.1secmail.com/api/v1/?action=readMessage&login={login}&domain={domain}&id={message['id']}"
|
| 209 |
+
message_response = session.get(message_url)
|
|
|
|
| 210 |
|
| 211 |
+
if message_response.status_code == 200:
|
| 212 |
+
full_message = message_response.json()
|
| 213 |
+
logging.info(f"Full message content found: {full_message}")
|
|
|
|
|
|
|
| 214 |
|
| 215 |
+
# 提取验证链接
|
| 216 |
+
match = re.search(r'https?://chat\.notdiamond\.ai/auth/confirm\?[^\s]+', full_message.get('body', ''))
|
| 217 |
+
if match:
|
| 218 |
+
verification_link = match.group(0)
|
| 219 |
+
logging.info(f"Verification link found: {verification_link}")
|
| 220 |
+
|
| 221 |
+
# 解析 URL 并获取参数
|
| 222 |
+
parsed_url = urlparse(verification_link)
|
| 223 |
+
query_params = parse_qs(parsed_url.query)
|
| 224 |
+
|
| 225 |
+
# 使用 Supabase API 进行验证
|
| 226 |
+
verify_url = "https://spuckhogycrxcbomznwo.supabase.co/auth/v1/verify"
|
| 227 |
+
headers = {
|
| 228 |
+
'apikey': SUPABASE_API_KEY,
|
| 229 |
+
'authorization': f'Bearer {SUPABASE_API_KEY}',
|
| 230 |
+
'content-type': 'application/json'
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
payload = {
|
| 234 |
+
'token_hash': query_params['token_hash'][0],
|
| 235 |
+
'type': 'signup' # 硬编码为 'signup'
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
verify_response = session.post(verify_url, headers=headers, json=payload)
|
| 239 |
+
|
| 240 |
+
logging.info(f"Verification response status: {verify_response.status_code}")
|
| 241 |
+
|
| 242 |
+
if verify_response.status_code == 200:
|
| 243 |
+
logging.info(f"Email verified for {email}")
|
| 244 |
+
return True
|
| 245 |
+
else:
|
| 246 |
+
logging.error(f"Failed to verify email for {email}: {verify_response.text}")
|
| 247 |
+
return False
|
| 248 |
else:
|
| 249 |
+
logging.error(f"Failed to extract verification link from email for {email}")
|
| 250 |
return False
|
| 251 |
+
time.sleep(5)
|
| 252 |
+
except Exception as e:
|
| 253 |
+
logging.error(f"Error during email verification: {e}")
|
| 254 |
+
|
| 255 |
logging.warning(f"No verification email found for {email}")
|
| 256 |
return False
|
| 257 |
|
|
|
|
| 278 |
password = generate_strong_password()
|
| 279 |
|
| 280 |
if register(email, password):
|
| 281 |
+
save_result = save_account(email, password)
|
| 282 |
+
if not save_result:
|
| 283 |
+
logging.error(f"Failed to save account {email}")
|
| 284 |
+
return None
|
| 285 |
+
|
| 286 |
if check_email(email):
|
| 287 |
+
logging.info(f"Account fully processed: {email}")
|
| 288 |
return {'email': email, 'password': password}
|
| 289 |
except Exception as e:
|
| 290 |
logging.error(f"Error processing account {email}: {e}")
|
|
|
|
| 294 |
num_accounts = 5 # 可以根据需要修改注册数量
|
| 295 |
successful_accounts = register_and_verify(num_accounts)
|
| 296 |
|
| 297 |
+
# 仅输出到控制台
|
| 298 |
print(f"Successfully registered {len(successful_accounts)} accounts")
|
| 299 |
for account in successful_accounts:
|
| 300 |
print(f"Email: {account['email']}, Password: {account['password']}")
|