feat: 增加自定义域名的支持
This commit is contained in:
2
.env.example
Normal file
2
.env.example
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
DOMAIN='xxxxx.me'
|
||||||
|
TEMP_MAIL='xxxxxx'
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -23,3 +23,5 @@ __pycache__/
|
|||||||
venv/
|
venv/
|
||||||
|
|
||||||
node_modules/
|
node_modules/
|
||||||
|
|
||||||
|
.env
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class BrowserManager:
|
|||||||
co.set_pref("credentials_enable_service", False)
|
co.set_pref("credentials_enable_service", False)
|
||||||
co.set_argument("--hide-crash-restore-bubble")
|
co.set_argument("--hide-crash-restore-bubble")
|
||||||
co.auto_port()
|
co.auto_port()
|
||||||
co.headless(True) # 生产环境使用无头模式
|
# co.headless(True) # 生产环境使用无头模式
|
||||||
|
|
||||||
# Mac 系统特殊处理
|
# Mac 系统特殊处理
|
||||||
if sys.platform == "darwin":
|
if sys.platform == "darwin":
|
||||||
|
|||||||
8
build.py
8
build.py
@@ -162,6 +162,14 @@ def build():
|
|||||||
else:
|
else:
|
||||||
subprocess.run(["cp", "config.ini.example", f"{output_dir}/config.ini"])
|
subprocess.run(["cp", "config.ini.example", f"{output_dir}/config.ini"])
|
||||||
|
|
||||||
|
# Copy .env.example file
|
||||||
|
if os.path.exists(".env.example"):
|
||||||
|
simulate_progress("Copying environment file...", 0.5)
|
||||||
|
if system == "windows":
|
||||||
|
subprocess.run(["copy", ".env.example", f"{output_dir}\\.env"], shell=True)
|
||||||
|
else:
|
||||||
|
subprocess.run(["cp", ".env.example", f"{output_dir}/.env"])
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"\n\033[92mBuild completed successfully! Output directory: {output_dir}\033[0m"
|
f"\n\033[92mBuild completed successfully! Output directory: {output_dir}\033[0m"
|
||||||
)
|
)
|
||||||
|
|||||||
37
config.py
Normal file
37
config.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
from dotenv import load_dotenv
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
def __init__(self):
|
||||||
|
# 获取应用程序的根目录路径
|
||||||
|
if getattr(sys, "frozen", False):
|
||||||
|
# 如果是打包后的可执行文件
|
||||||
|
application_path = os.path.dirname(sys.executable)
|
||||||
|
else:
|
||||||
|
# 如果是开发环境
|
||||||
|
application_path = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
# 指定 .env 文件的路径
|
||||||
|
dotenv_path = os.path.join(application_path, ".env")
|
||||||
|
|
||||||
|
# 加载 .env 文件
|
||||||
|
load_dotenv(dotenv_path)
|
||||||
|
|
||||||
|
def get_temp_mail(self):
|
||||||
|
return os.getenv("TEMP_MAIL")
|
||||||
|
|
||||||
|
def get_domain(self):
|
||||||
|
return os.getenv("DOMAIN")
|
||||||
|
|
||||||
|
|
||||||
|
# 使用示例
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
config = Config()
|
||||||
|
print("环境变量加载成功!")
|
||||||
|
print(f"临时邮箱: {config.get_temp_mail()}")
|
||||||
|
print(f"域名: {config.get_domain()}")
|
||||||
|
except ValueError as e:
|
||||||
|
print(f"错误: {e}")
|
||||||
@@ -14,7 +14,7 @@ from logger import logging
|
|||||||
from browser_utils import BrowserManager
|
from browser_utils import BrowserManager
|
||||||
from get_email_code import EmailVerificationHandler
|
from get_email_code import EmailVerificationHandler
|
||||||
from logo import print_logo
|
from logo import print_logo
|
||||||
import psutil
|
from config import Config
|
||||||
|
|
||||||
|
|
||||||
def handle_turnstile(tab):
|
def handle_turnstile(tab):
|
||||||
@@ -191,7 +191,6 @@ def sign_up_account(browser, tab):
|
|||||||
class EmailGenerator:
|
class EmailGenerator:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
domain="mailto.plus",
|
|
||||||
password="".join(
|
password="".join(
|
||||||
random.choices(
|
random.choices(
|
||||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*",
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*",
|
||||||
@@ -201,7 +200,7 @@ class EmailGenerator:
|
|||||||
first_name="yuyan",
|
first_name="yuyan",
|
||||||
last_name="peng",
|
last_name="peng",
|
||||||
):
|
):
|
||||||
self.domain = domain
|
self.domain = Config().get_domain()
|
||||||
self.default_password = password
|
self.default_password = password
|
||||||
self.default_first_name = first_name
|
self.default_first_name = first_name
|
||||||
self.default_last_name = last_name
|
self.default_last_name = last_name
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
from DrissionPage.common import Keys
|
from DrissionPage.common import Keys
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
|
from config import Config
|
||||||
|
|
||||||
|
|
||||||
class EmailVerificationHandler:
|
class EmailVerificationHandler:
|
||||||
def __init__(self, browser, mail_url="https://tempmail.plus"):
|
def __init__(self, browser, mail_url="https://tempmail.plus"):
|
||||||
self.browser = browser
|
self.browser = browser
|
||||||
self.mail_url = mail_url
|
self.mail_url = mail_url
|
||||||
|
self.username = Config().get_temp_mail()
|
||||||
|
|
||||||
def get_verification_code(self, email):
|
def get_verification_code(self):
|
||||||
username = email.split("@")[0]
|
|
||||||
code = None
|
code = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -19,7 +20,7 @@ class EmailVerificationHandler:
|
|||||||
self.browser.activate_tab(tab_mail)
|
self.browser.activate_tab(tab_mail)
|
||||||
|
|
||||||
# 输入用户名
|
# 输入用户名
|
||||||
self._input_username(tab_mail, username)
|
self._input_username(tab_mail)
|
||||||
|
|
||||||
# 等待并获取最新邮件
|
# 等待并获取最新邮件
|
||||||
code = self._get_latest_mail_code(tab_mail)
|
code = self._get_latest_mail_code(tab_mail)
|
||||||
@@ -35,14 +36,14 @@ class EmailVerificationHandler:
|
|||||||
|
|
||||||
return code
|
return code
|
||||||
|
|
||||||
def _input_username(self, tab, username):
|
def _input_username(self, tab):
|
||||||
while True:
|
while True:
|
||||||
if tab.ele("@id=pre_button"):
|
if tab.ele("@id=pre_button"):
|
||||||
tab.actions.click("@id=pre_button")
|
tab.actions.click("@id=pre_button")
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
tab.run_js('document.getElementById("pre_button").value = ""')
|
tab.run_js('document.getElementById("pre_button").value = ""')
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
tab.actions.input(username).key_down(Keys.ENTER).key_up(Keys.ENTER)
|
tab.actions.input(self.username).key_down(Keys.ENTER).key_up(Keys.ENTER)
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
DrissionPage==4.1.0.9
|
DrissionPage==4.1.0.9
|
||||||
colorama==0.4.6
|
colorama==0.4.6
|
||||||
|
python-dotenv==1.0.0
|
||||||
|
|||||||
Reference in New Issue
Block a user