准备创建mysqlv1分支的提交

This commit is contained in:
huangzhenpc
2025-04-01 15:43:27 +08:00
parent cc2a3a34e3
commit 7dad9f6b2f
13 changed files with 1248 additions and 149 deletions

View File

@@ -39,29 +39,44 @@ class EmailManager:
"""批量获取未使用的邮箱账号"""
logger.info(f"尝试获取 {num} 个未使用的邮箱账号")
query = '''
UPDATE email_accounts
SET in_use = 1, updated_at = CURRENT_TIMESTAMP
WHERE id IN (
SELECT id FROM email_accounts
WHERE in_use = 0 AND sold = 0 AND status = 'pending'
LIMIT ?
)
RETURNING id, email, password, client_id, refresh_token
'''
# 1. 先查询符合条件的账号ID列表
select_query = """
SELECT id, email, password, client_id, refresh_token
FROM email_accounts
WHERE in_use = 0 AND sold = 0 AND status = 'pending'
LIMIT %s
"""
accounts = await self.db.fetch_all(select_query, (num,))
if not accounts:
logger.debug("没有找到符合条件的账号")
return []
results = await self.db.fetch_all(query, (num,))
logger.debug(f"实际获取到 {len(results)} 个账号")
# 2. 提取账号ID列表
account_ids = [account['id'] for account in accounts]
# 3. 更新这些账号的状态
if account_ids:
placeholders = ', '.join(['%s' for _ in account_ids])
update_query = f"""
UPDATE email_accounts
SET in_use = 1, updated_at = CURRENT_TIMESTAMP
WHERE id IN ({placeholders})
"""
await self.db.execute(update_query, tuple(account_ids))
# 4. 返回账号数据
logger.debug(f"实际获取到 {len(accounts)} 个账号")
return [
EmailAccount(
id=row[0],
email=row[1],
password=row[2],
client_id=row[3],
refresh_token=row[4],
id=row['id'],
email=row['email'],
password=row['password'],
client_id=row['client_id'],
refresh_token=row['refresh_token'],
in_use=True
)
for row in results
for row in accounts
]
async def update_account_status(self, account_id: int, status: str):
@@ -69,10 +84,10 @@ class EmailManager:
query = '''
UPDATE email_accounts
SET
status = ?,
status = %s,
in_use = 0,
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
WHERE id = %s
'''
await self.db.execute(query, (status, account_id))
@@ -81,14 +96,14 @@ class EmailManager:
query = '''
UPDATE email_accounts
SET
cursor_password = ?,
cursor_cookie = ?,
cursor_token = ?,
cursor_password = %s,
cursor_cookie = %s,
cursor_token = %s,
in_use = 0,
sold = 1,
status = 'success',
updated_at = CURRENT_TIMESTAMP
WHERE id = ?
WHERE id = %s
'''
await self.db.execute(query, (cursor_password, cursor_cookie, cursor_token, account_id))
@@ -97,7 +112,7 @@ class EmailManager:
query = '''
UPDATE email_accounts
SET in_use = 0, updated_at = CURRENT_TIMESTAMP
WHERE id = ?
WHERE id = %s
'''
await self.db.execute(query, (account_id,))
@@ -236,10 +251,10 @@ class EmailManager:
logger.debug(f"从文本中提取到验证码: {code}")
return code
logger.warning(f"[{email}] 未能从邮件中提取到验证码")
logger.debug(f"[{email}] 邮件内容预览: " + body[:200])
logger.warning(f"未能从邮件中提取到验证码")
logger.debug(f"邮件内容预览: " + body[:200])
return None
except Exception as e:
logger.error(f"[{email}] 提取验证码失败: {str(e)}")
logger.error(f"提取验证码失败: {str(e)}")
return None

View File

@@ -14,7 +14,7 @@ class ProxyPool:
async def batch_get(self, num: int) -> List[str]:
"""获取num个代理"""
# 临时代理
return ['http://127.0.0.1:3057'] * num
return ['http://60.188.79.110:20051'] * num
try:
response = await self.fetch_manager.request(