mirror of
https://github.com/NanmiCoder/MediaCrawler.git
synced 2026-05-08 03:27:36 +08:00
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:
@@ -21,7 +21,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author : relakkes@gmail.com
|
||||
# @Time : 2023/12/2 12:52
|
||||
# @Desc : 时间相关的工具函数
|
||||
# @Desc : Time utility functions
|
||||
|
||||
import time
|
||||
from datetime import datetime, timedelta, timezone
|
||||
@@ -29,7 +29,7 @@ from datetime import datetime, timedelta, timezone
|
||||
|
||||
def get_current_timestamp() -> int:
|
||||
"""
|
||||
获取当前的时间戳(13 位):1701493264496
|
||||
Get current timestamp (13 digits): 1701493264496
|
||||
:return:
|
||||
"""
|
||||
return int(time.time() * 1000)
|
||||
@@ -37,21 +37,21 @@ def get_current_timestamp() -> int:
|
||||
|
||||
def get_current_time() -> str:
|
||||
"""
|
||||
获取当前的时间:'2023-12-02 13:01:23'
|
||||
Get current time: '2023-12-02 13:01:23'
|
||||
:return:
|
||||
"""
|
||||
return time.strftime('%Y-%m-%d %X', time.localtime())
|
||||
|
||||
def get_current_time_hour() -> str:
|
||||
"""
|
||||
获取当前的时间:'2023-12-02-13'
|
||||
Get current time with hour: '2023-12-02-13'
|
||||
:return:
|
||||
"""
|
||||
return time.strftime('%Y-%m-%d-%H', time.localtime())
|
||||
|
||||
def get_current_date() -> str:
|
||||
"""
|
||||
获取当前的日期:'2023-12-02'
|
||||
Get current date: '2023-12-02'
|
||||
:return:
|
||||
"""
|
||||
return time.strftime('%Y-%m-%d', time.localtime())
|
||||
@@ -59,7 +59,7 @@ def get_current_date() -> str:
|
||||
|
||||
def get_time_str_from_unix_time(unixtime):
|
||||
"""
|
||||
unix 整数类型时间戳 ==> 字符串日期时间
|
||||
Unix integer timestamp ==> datetime string
|
||||
:param unixtime:
|
||||
:return:
|
||||
"""
|
||||
@@ -70,7 +70,7 @@ def get_time_str_from_unix_time(unixtime):
|
||||
|
||||
def get_date_str_from_unix_time(unixtime):
|
||||
"""
|
||||
unix 整数类型时间戳 ==> 字符串日期
|
||||
Unix integer timestamp ==> date string
|
||||
:param unixtime:
|
||||
:return:
|
||||
"""
|
||||
@@ -81,7 +81,7 @@ def get_date_str_from_unix_time(unixtime):
|
||||
|
||||
def get_unix_time_from_time_str(time_str):
|
||||
"""
|
||||
字符串时间 ==> unix 整数类型时间戳,精确到秒
|
||||
Time string ==> Unix integer timestamp, precise to seconds
|
||||
:param time_str:
|
||||
:return:
|
||||
"""
|
||||
@@ -99,34 +99,34 @@ def get_unix_timestamp():
|
||||
|
||||
|
||||
def rfc2822_to_china_datetime(rfc2822_time):
|
||||
# 定义RFC 2822格式
|
||||
# Define RFC 2822 format
|
||||
rfc2822_format = "%a %b %d %H:%M:%S %z %Y"
|
||||
|
||||
# 将RFC 2822时间字符串转换为datetime对象
|
||||
# Convert RFC 2822 time string to datetime object
|
||||
dt_object = datetime.strptime(rfc2822_time, rfc2822_format)
|
||||
|
||||
# 将datetime对象的时区转换为中国时区
|
||||
# Convert datetime object timezone to China timezone
|
||||
dt_object_china = dt_object.astimezone(timezone(timedelta(hours=8)))
|
||||
return dt_object_china
|
||||
|
||||
|
||||
def rfc2822_to_timestamp(rfc2822_time):
|
||||
# 定义RFC 2822格式
|
||||
# Define RFC 2822 format
|
||||
rfc2822_format = "%a %b %d %H:%M:%S %z %Y"
|
||||
|
||||
# 将RFC 2822时间字符串转换为datetime对象
|
||||
# Convert RFC 2822 time string to datetime object
|
||||
dt_object = datetime.strptime(rfc2822_time, rfc2822_format)
|
||||
|
||||
# 将datetime对象转换为UTC时间
|
||||
# Convert datetime object to UTC time
|
||||
dt_utc = dt_object.replace(tzinfo=timezone.utc)
|
||||
|
||||
# 计算UTC时间对应的Unix时间戳
|
||||
# Calculate Unix timestamp from UTC time
|
||||
timestamp = int(dt_utc.timestamp())
|
||||
|
||||
return timestamp
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 示例用法
|
||||
# Example usage
|
||||
_rfc2822_time = "Sat Dec 23 17:12:54 +0800 2023"
|
||||
print(rfc2822_to_china_datetime(_rfc2822_time))
|
||||
|
||||
Reference in New Issue
Block a user