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

24
cache/abs_cache.py vendored
View File

@@ -20,9 +20,9 @@
# -*- coding: utf-8 -*-
# @Author : relakkes@gmail.com
# @Name : 程序员阿江-Relakkes
# @Name : Programmer AJiang-Relakkes
# @Time : 2024/6/2 11:06
# @Desc : 抽象类
# @Desc : Abstract class
from abc import ABC, abstractmethod
from typing import Any, List, Optional
@@ -33,9 +33,9 @@ class AbstractCache(ABC):
@abstractmethod
def get(self, key: str) -> Optional[Any]:
"""
从缓存中获取键的值。
这是一个抽象方法。子类必须实现这个方法。
:param key:
Get the value of a key from the cache.
This is an abstract method. Subclasses must implement this method.
:param key: The key
:return:
"""
raise NotImplementedError
@@ -43,11 +43,11 @@ class AbstractCache(ABC):
@abstractmethod
def set(self, key: str, value: Any, expire_time: int) -> None:
"""
将键的值设置到缓存中。
这是一个抽象方法。子类必须实现这个方法。
:param key:
:param value:
:param expire_time: 过期时间
Set the value of a key in the cache.
This is an abstract method. Subclasses must implement this method.
:param key: The key
:param value: The value
:param expire_time: Expiration time
:return:
"""
raise NotImplementedError
@@ -55,8 +55,8 @@ class AbstractCache(ABC):
@abstractmethod
def keys(self, pattern: str) -> List[str]:
"""
获取所有符合pattern的key
:param pattern: 匹配模式
Get all keys matching the pattern
:param pattern: Matching pattern
:return:
"""
raise NotImplementedError

View File

@@ -20,23 +20,23 @@
# -*- coding: utf-8 -*-
# @Author : relakkes@gmail.com
# @Name : 程序员阿江-Relakkes
# @Name : Programmer AJiang-Relakkes
# @Time : 2024/6/2 11:23
# @Desc :
class CacheFactory:
"""
缓存工厂类
Cache factory class
"""
@staticmethod
def create_cache(cache_type: str, *args, **kwargs):
"""
创建缓存对象
:param cache_type: 缓存类型
:param args: 参数
:param kwargs: 关键字参数
Create cache object
:param cache_type: Cache type
:param args: Arguments
:param kwargs: Keyword arguments
:return:
"""
if cache_type == 'memory':

32
cache/local_cache.py vendored
View File

@@ -20,9 +20,9 @@
# -*- coding: utf-8 -*-
# @Author : relakkes@gmail.com
# @Name : 程序员阿江-Relakkes
# @Name : Programmer AJiang-Relakkes
# @Time : 2024/6/2 11:05
# @Desc : 本地缓存
# @Desc : Local cache
import asyncio
import time
@@ -35,19 +35,19 @@ class ExpiringLocalCache(AbstractCache):
def __init__(self, cron_interval: int = 10):
"""
初始化本地缓存
:param cron_interval: 定时清楚cache的时间间隔
Initialize local cache
:param cron_interval: Time interval for scheduled cache cleanup
:return:
"""
self._cron_interval = cron_interval
self._cache_container: Dict[str, Tuple[Any, float]] = {}
self._cron_task: Optional[asyncio.Task] = None
# 开启定时清理任务
# Start scheduled cleanup task
self._schedule_clear()
def __del__(self):
"""
析构函数,清理定时任务
Destructor function, cleanup scheduled task
:return:
"""
if self._cron_task is not None:
@@ -55,7 +55,7 @@ class ExpiringLocalCache(AbstractCache):
def get(self, key: str) -> Optional[Any]:
"""
从缓存中获取键的值
Get the value of a key from the cache
:param key:
:return:
"""
@@ -63,7 +63,7 @@ class ExpiringLocalCache(AbstractCache):
if value is None:
return None
# 如果键已过期,则删除键并返回None
# If the key has expired, delete it and return None
if expire_time < time.time():
del self._cache_container[key]
return None
@@ -72,7 +72,7 @@ class ExpiringLocalCache(AbstractCache):
def set(self, key: str, value: Any, expire_time: int) -> None:
"""
将键的值设置到缓存中
Set the value of a key in the cache
:param key:
:param value:
:param expire_time:
@@ -82,14 +82,14 @@ class ExpiringLocalCache(AbstractCache):
def keys(self, pattern: str) -> List[str]:
"""
获取所有符合pattern的key
:param pattern: 匹配模式
Get all keys matching the pattern
:param pattern: Matching pattern
:return:
"""
if pattern == '*':
return list(self._cache_container.keys())
# 本地缓存通配符暂时将*替换为空
# For local cache wildcard, temporarily replace * with empty string
if '*' in pattern:
pattern = pattern.replace('*', '')
@@ -97,7 +97,7 @@ class ExpiringLocalCache(AbstractCache):
def _schedule_clear(self):
"""
开启定时清理任务,
Start scheduled cleanup task
:return:
"""
@@ -111,7 +111,7 @@ class ExpiringLocalCache(AbstractCache):
def _clear(self):
"""
根据过期时间清理缓存
Clean up cache based on expiration time
:return:
"""
for key, (value, expire_time) in self._cache_container.items():
@@ -120,7 +120,7 @@ class ExpiringLocalCache(AbstractCache):
async def _start_clear_cron(self):
"""
开启定时清理任务
Start scheduled cleanup task
:return:
"""
while True:
@@ -130,7 +130,7 @@ class ExpiringLocalCache(AbstractCache):
if __name__ == '__main__':
cache = ExpiringLocalCache(cron_interval=2)
cache.set('name', '程序员阿江-Relakkes', 3)
cache.set('name', 'Programmer AJiang-Relakkes', 3)
print(cache.get('key'))
print(cache.keys("*"))
time.sleep(4)

16
cache/redis_cache.py vendored
View File

@@ -20,9 +20,9 @@
# -*- coding: utf-8 -*-
# @Author : relakkes@gmail.com
# @Name : 程序员阿江-Relakkes
# @Name : Programmer AJiang-Relakkes
# @Time : 2024/5/29 22:57
# @Desc : RedisCache实现
# @Desc : RedisCache implementation
import pickle
import time
from typing import Any, List
@@ -36,13 +36,13 @@ from config import db_config
class RedisCache(AbstractCache):
def __init__(self) -> None:
# 连接redis, 返回redis客户端
# Connect to redis, return redis client
self._redis_client = self._connet_redis()
@staticmethod
def _connet_redis() -> Redis:
"""
连接redis, 返回redis客户端, 这里按需配置redis连接信息
Connect to redis, return redis client, configure redis connection information as needed
:return:
"""
return Redis(
@@ -54,7 +54,7 @@ class RedisCache(AbstractCache):
def get(self, key: str) -> Any:
"""
从缓存中获取键的值, 并且反序列化
Get the value of a key from the cache and deserialize it
:param key:
:return:
"""
@@ -65,7 +65,7 @@ class RedisCache(AbstractCache):
def set(self, key: str, value: Any, expire_time: int) -> None:
"""
将键的值设置到缓存中, 并且序列化
Set the value of a key in the cache and serialize it
:param key:
:param value:
:param expire_time:
@@ -75,7 +75,7 @@ class RedisCache(AbstractCache):
def keys(self, pattern: str) -> List[str]:
"""
获取所有符合pattern的key
Get all keys matching the pattern
"""
return [key.decode() for key in self._redis_client.keys(pattern)]
@@ -83,7 +83,7 @@ class RedisCache(AbstractCache):
if __name__ == '__main__':
redis_cache = RedisCache()
# basic usage
redis_cache.set("name", "程序员阿江-Relakkes", 1)
redis_cache.set("name", "Programmer AJiang-Relakkes", 1)
print(redis_cache.get("name")) # Relakkes
print(redis_cache.keys("*")) # ['name']
time.sleep(2)