feat: 增加自定义域名的支持

This commit is contained in:
cheng zhen
2025-01-10 19:33:45 +08:00
parent 1da2296372
commit 331b55516b
8 changed files with 59 additions and 9 deletions

2
.env.example Normal file
View File

@@ -0,0 +1,2 @@
DOMAIN='xxxxx.me'
TEMP_MAIL='xxxxxx'

2
.gitignore vendored
View File

@@ -23,3 +23,5 @@ __pycache__/
venv/
node_modules/
.env

View File

@@ -29,7 +29,7 @@ class BrowserManager:
co.set_pref("credentials_enable_service", False)
co.set_argument("--hide-crash-restore-bubble")
co.auto_port()
co.headless(True) # 生产环境使用无头模式
# co.headless(True) # 生产环境使用无头模式
# Mac 系统特殊处理
if sys.platform == "darwin":

View File

@@ -162,6 +162,14 @@ def build():
else:
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(
f"\n\033[92mBuild completed successfully! Output directory: {output_dir}\033[0m"
)

37
config.py Normal file
View 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}")

View File

@@ -14,7 +14,7 @@ from logger import logging
from browser_utils import BrowserManager
from get_email_code import EmailVerificationHandler
from logo import print_logo
import psutil
from config import Config
def handle_turnstile(tab):
@@ -191,7 +191,6 @@ def sign_up_account(browser, tab):
class EmailGenerator:
def __init__(
self,
domain="mailto.plus",
password="".join(
random.choices(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*",
@@ -201,7 +200,7 @@ class EmailGenerator:
first_name="yuyan",
last_name="peng",
):
self.domain = domain
self.domain = Config().get_domain()
self.default_password = password
self.default_first_name = first_name
self.default_last_name = last_name

View File

@@ -1,15 +1,16 @@
from DrissionPage.common import Keys
import time
import re
from config import Config
class EmailVerificationHandler:
def __init__(self, browser, mail_url="https://tempmail.plus"):
self.browser = browser
self.mail_url = mail_url
self.username = Config().get_temp_mail()
def get_verification_code(self, email):
username = email.split("@")[0]
def get_verification_code(self):
code = None
try:
@@ -19,7 +20,7 @@ class EmailVerificationHandler:
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)
@@ -35,14 +36,14 @@ class EmailVerificationHandler:
return code
def _input_username(self, tab, username):
def _input_username(self, tab):
while True:
if tab.ele("@id=pre_button"):
tab.actions.click("@id=pre_button")
time.sleep(0.5)
tab.run_js('document.getElementById("pre_button").value = ""')
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
time.sleep(1)

View File

@@ -1,2 +1,3 @@
DrissionPage==4.1.0.9
colorama==0.4.6
python-dotenv==1.0.0