保存现有功能 增加域名和添加时间关联

This commit is contained in:
huangzhenpc
2025-04-07 15:13:07 +08:00
parent 69bf430525
commit 85c3095e98
2 changed files with 72 additions and 39 deletions

View File

@@ -385,42 +385,63 @@ class AutoCursorService:
self.registration_process = None
async def upload_accounts(self):
"""上传已注册成功的账号"""
logger.info("开始上传注册成功的账号")
try:
# 使用subprocess运行upload_account.py
if sys.platform.startswith("win"):
process = subprocess.Popen(
["python", "upload_account.py"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
creationflags=subprocess.CREATE_NO_WINDOW
)
else:
process = subprocess.Popen(
["python3", "upload_account.py"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
# 等待进程完成
stdout, stderr = process.communicate()
if process.returncode != 0:
logger.error(f"上传账号进程异常终止,退出码: {process.returncode}")
if stderr:
logger.error(f"错误输出: {stderr.decode('utf-8', errors='ignore')}")
else:
logger.info("账号上传完成")
if stdout:
# 只记录最后几行输出
output_lines = stdout.decode('utf-8', errors='ignore').strip().split('\n')
for line in output_lines[-5:]:
logger.info(f"Upload: {line}")
async def upload_accounts(self, accounts: List[Dict[str, Any]]) -> bool:
"""上传账号到API
Args:
accounts: 要上传的账号列表每个账号包含email、password、cursor_password等信息
Returns:
bool: 是否上传成功
"""
if not accounts:
return True
url = f"{self.api_base_url}/commonadd"
try:
# 准备上传数据
upload_data = []
for account in accounts:
upload_item = {
"email": account["email"],
"email_password": account["password"], # 使用password作为email_password
"cursor_email": account["email"],
"cursor_password": account["cursor_password"],
"cookie": account["cursor_cookie"] or "",
"token": account.get("cursor_jwt", ""), # 使用cursor_jwt作为token
"hostname": self.hostname
}
upload_data.append(upload_item)
logger.debug(f"准备上传 {len(upload_data)} 个账号")
# 发送请求
async with aiohttp.ClientSession() as session:
async with session.post(
url,
json=upload_data,
proxy=self.proxy,
ssl=False
) as response:
if response.status != 200:
logger.error(f"上传账号API请求失败状态码: {response.status}")
return False
data = await response.json()
if data.get("code") != 0:
logger.error(f"上传账号API返回错误: {data.get('msg', 'Unknown error')}")
return False
success_count = data.get("data", {}).get("success", 0)
failed_count = data.get("data", {}).get("failed", 0)
logger.info(f"账号上传结果: 成功 {success_count}, 失败 {failed_count}")
return success_count > 0
except Exception as e:
logger.error(f"执行账号上传脚本时出错: {e}")
logger.error(f"上传账号时出错: {e}")
return False
async def run(self):
"""运行服务主循环"""

22
main.py
View File

@@ -18,6 +18,7 @@ from services.proxy_pool import ProxyPool
from services.token_pool import TokenPool
from services.self_hosted_email import SelfHostedEmail
from upload_account import AccountUploader
from auto_cursor_service import AutoCursorService
class CursorRegister:
@@ -208,12 +209,23 @@ class CursorRegister:
skipped += 1
else:
successful.append(result)
# 添加详细的账号信息日志
self.logger.info("=" * 50)
self.logger.info(f"账号 {i+1} 注册成功:")
self.logger.info(f"邮箱: {result['email']}")
self.logger.info(f"邮箱密码: {result['email_password']}")
self.logger.info(f"Cursor密码: {result['cursor_password']}")
# 只显示token的前30个字符避免日志过长
token = result.get('cursor_jwt', '')
if token:
self.logger.info(f"Token: {token[:30]}...")
self.logger.info("=" * 50)
# 6. 直接上传成功注册的账号
if successful:
try:
uploader = AccountUploader()
await uploader.initialize()
service = AutoCursorService()
await service.initialize()
# 准备上传数据
upload_data = []
@@ -223,13 +235,13 @@ class CursorRegister:
"password": account["email_password"],
"cursor_password": account["cursor_password"],
"cursor_cookie": account["cursor_cookie"],
"cursor_token": account.get("cursor_jwt", "")
"cursor_jwt": account.get("cursor_jwt", "")
}
upload_data.append(upload_item)
# 上传账号
await uploader.upload_accounts(upload_data)
await uploader.cleanup()
await service.upload_accounts(upload_data)
await service.cleanup()
self.logger.info(f"成功上传 {len(upload_data)} 个账号到服务器")
except Exception as e:
self.logger.error(f"上传账号时发生错误: {str(e)}")