x
This commit is contained in:
61
import_emails.py
Normal file
61
import_emails.py
Normal file
@@ -0,0 +1,61 @@
|
||||
import asyncio
|
||||
|
||||
import aiosqlite
|
||||
from loguru import logger
|
||||
|
||||
from core.config import Config
|
||||
|
||||
|
||||
async def import_emails(config: Config, file_path: str):
|
||||
"""导入邮箱账号到数据库"""
|
||||
DEFAULT_CLIENT_ID = "9e5f94bc-e8a4-4e73-b8be-63364c29d753"
|
||||
|
||||
async with aiosqlite.connect(config.database_config.path) as db:
|
||||
# 创建表
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS email_accounts (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
email TEXT UNIQUE NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
client_id TEXT NOT NULL,
|
||||
refresh_token TEXT NOT NULL,
|
||||
in_use BOOLEAN DEFAULT 0,
|
||||
cursor_password TEXT,
|
||||
cursor_cookie TEXT,
|
||||
cursor_token TEXT,
|
||||
sold BOOLEAN DEFAULT 0,
|
||||
status TEXT DEFAULT 'pending',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
''')
|
||||
|
||||
# 读取文件并导入数据
|
||||
count = 0
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
for line in f:
|
||||
if line.strip():
|
||||
try:
|
||||
email, password, client_id, refresh_token = line.strip().split('----')
|
||||
await db.execute('''
|
||||
INSERT INTO email_accounts (
|
||||
email, password, client_id, refresh_token, status
|
||||
) VALUES (?, ?, ?, ?, 'pending')
|
||||
''', (email, password, client_id, refresh_token))
|
||||
count += 1
|
||||
except aiosqlite.IntegrityError:
|
||||
logger.warning(f"重复的邮箱: {email}")
|
||||
except ValueError:
|
||||
logger.error(f"无效的数据行: {line.strip()}")
|
||||
|
||||
await db.commit()
|
||||
logger.success(f"成功导入 {count} 个邮箱账号")
|
||||
|
||||
|
||||
async def main():
|
||||
config = Config.from_yaml()
|
||||
await import_emails(config, "email.txt")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user