i18n: translate all Chinese comments, docstrings, and logger messages to English

Comprehensive translation of Chinese text to English across the entire codebase:

- api/: FastAPI server documentation and logger messages
- cache/: Cache abstraction layer comments and docstrings
- database/: Database models and MongoDB store documentation
- media_platform/: All platform crawlers (Bilibili, Douyin, Kuaishou, Tieba, Weibo, Xiaohongshu, Zhihu)
- model/: Data model documentation
- proxy/: Proxy pool and provider documentation
- store/: Data storage layer comments
- tools/: Utility functions and browser automation
- test/: Test file documentation

Preserved: Chinese disclaimer header (lines 10-18) for legal compliance

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
程序员阿江(Relakkes)
2025-12-26 23:27:19 +08:00
parent 1544d13dd5
commit 157ddfb21b
93 changed files with 1971 additions and 1955 deletions

View File

@@ -17,9 +17,9 @@
# 使用本代码即表示您同意遵守上述原则和LICENSE中的所有条款。
# persist-1<persist1@126.com>
# 原因:将 db.py 改造为模块,移除直接执行入口,修复相对导入问题。
# 副作用:无
# 回滚策略:还原此文件。
# Reason: Refactored db.py into a module, removed direct execution entry point, fixed relative import issues.
# Side effects: None
# Rollback strategy: Restore this file.
import asyncio
import sys
from pathlib import Path

View File

@@ -406,9 +406,9 @@ class ZhihuContent(Base):
last_modify_ts = Column(BigInteger)
# persist-1<persist1@126.com>
# 原因:修复 ORM 模型定义错误,确保与数据库表结构一致。
# 副作用:无
# 回滚策略:还原此行
# Reason: Fixed ORM model definition error, ensuring consistency with database table structure.
# Side effects: None
# Rollback strategy: Restore this line
class ZhihuComment(Base):
__tablename__ = 'zhihu_comment'

View File

@@ -16,7 +16,7 @@
# 详细许可条款请参阅项目根目录下的LICENSE文件。
# 使用本代码即表示您同意遵守上述原则和LICENSE中的所有条款。
"""MongoDB存储基类:提供连接管理和通用存储方法"""
"""MongoDB storage base class: Provides connection management and common storage methods"""
import asyncio
from typing import Dict, List, Optional
from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase, AsyncIOMotorCollection
@@ -25,7 +25,7 @@ from tools import utils
class MongoDBConnection:
"""MongoDB连接管理(单例模式)"""
"""MongoDB connection management (singleton pattern)"""
_instance = None
_client: Optional[AsyncIOMotorClient] = None
_db: Optional[AsyncIOMotorDatabase] = None
@@ -37,7 +37,7 @@ class MongoDBConnection:
return cls._instance
async def get_client(self) -> AsyncIOMotorClient:
"""获取客户端"""
"""Get client"""
if self._client is None:
async with self._lock:
if self._client is None:
@@ -45,7 +45,7 @@ class MongoDBConnection:
return self._client
async def get_db(self) -> AsyncIOMotorDatabase:
"""获取数据库"""
"""Get database"""
if self._db is None:
async with self._lock:
if self._db is None:
@@ -53,7 +53,7 @@ class MongoDBConnection:
return self._db
async def _connect(self):
"""建立连接"""
"""Establish connection"""
try:
mongo_config = db_config.mongodb_config
host = mongo_config["host"]
@@ -62,14 +62,14 @@ class MongoDBConnection:
password = mongo_config["password"]
db_name = mongo_config["db_name"]
# 构建连接URL有认证/无认证)
# Build connection URL (with/without authentication)
if user and password:
connection_url = f"mongodb://{user}:{password}@{host}:{port}/"
else:
connection_url = f"mongodb://{host}:{port}/"
self._client = AsyncIOMotorClient(connection_url, serverSelectionTimeoutMS=5000)
await self._client.server_info() # 测试连接
await self._client.server_info() # Test connection
self._db = self._client[db_name]
utils.logger.info(f"[MongoDBConnection] Connected to {host}:{port}/{db_name}")
except Exception as e:
@@ -77,7 +77,7 @@ class MongoDBConnection:
raise
async def close(self):
"""关闭连接"""
"""Close connection"""
if self._client is not None:
self._client.close()
self._client = None
@@ -86,24 +86,24 @@ class MongoDBConnection:
class MongoDBStoreBase:
"""MongoDB存储基类提供通用的CRUD操作"""
"""MongoDB storage base class: Provides common CRUD operations"""
def __init__(self, collection_prefix: str):
"""初始化存储基类
"""Initialize storage base class
Args:
collection_prefix: 平台前缀(xhs/douyin/bilibili等)
collection_prefix: Platform prefix (xhs/douyin/bilibili, etc.)
"""
self.collection_prefix = collection_prefix
self._connection = MongoDBConnection()
async def get_collection(self, collection_suffix: str) -> AsyncIOMotorCollection:
"""获取集合:{prefix}_{suffix}"""
"""Get collection: {prefix}_{suffix}"""
db = await self._connection.get_db()
collection_name = f"{self.collection_prefix}_{collection_suffix}"
return db[collection_name]
async def save_or_update(self, collection_suffix: str, query: Dict, data: Dict) -> bool:
"""保存或更新数据(upsert"""
"""Save or update data (upsert)"""
try:
collection = await self.get_collection(collection_suffix)
await collection.update_one(query, {"$set": data}, upsert=True)
@@ -113,7 +113,7 @@ class MongoDBStoreBase:
return False
async def find_one(self, collection_suffix: str, query: Dict) -> Optional[Dict]:
"""查询单条数据"""
"""Query a single record"""
try:
collection = await self.get_collection(collection_suffix)
return await collection.find_one(query)
@@ -122,7 +122,7 @@ class MongoDBStoreBase:
return None
async def find_many(self, collection_suffix: str, query: Dict, limit: int = 0) -> List[Dict]:
"""查询多条数据limit=0表示不限制"""
"""Query multiple records (limit=0 means no limit)"""
try:
collection = await self.get_collection(collection_suffix)
cursor = collection.find(query)
@@ -134,7 +134,7 @@ class MongoDBStoreBase:
return []
async def create_index(self, collection_suffix: str, keys: List[tuple], unique: bool = False):
"""创建索引:keys=[("field", 1)]"""
"""Create index: keys=[("field", 1)]"""
try:
collection = await self.get_collection(collection_suffix)
await collection.create_index(keys, unique=unique)