This commit is contained in:
parent
4bbe65d212
commit
94c43069c8
2
.github/workflows/OpenWRT介绍.yml
vendored
2
.github/workflows/OpenWRT介绍.yml
vendored
@ -31,7 +31,7 @@ jobs:
|
|||||||
# 将多行 JSON 配置内容从 Secrets 中写入 trojan-go-config.json 文件
|
# 将多行 JSON 配置内容从 Secrets 中写入 trojan-go-config.json 文件
|
||||||
echo "$TROJAN_GO_CONFIG" > trojan-go-config.json
|
echo "$TROJAN_GO_CONFIG" > trojan-go-config.json
|
||||||
#打印配置文件内容
|
#打印配置文件内容
|
||||||
cat trojan-go-config.json
|
#cat trojan-go-config.json
|
||||||
env:
|
env:
|
||||||
TROJAN_GO_CONFIG: ${{ secrets.TROJAN_GO_CONFIG }}
|
TROJAN_GO_CONFIG: ${{ secrets.TROJAN_GO_CONFIG }}
|
||||||
|
|
||||||
|
2
.github/workflows/翻译更新日志.yml
vendored
2
.github/workflows/翻译更新日志.yml
vendored
@ -27,8 +27,6 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
# 将多行 JSON 配置内容从 Secrets 中写入 trojan-go-config.json 文件
|
# 将多行 JSON 配置内容从 Secrets 中写入 trojan-go-config.json 文件
|
||||||
echo "$TROJAN_GO_CONFIG" > trojan-go-config.json
|
echo "$TROJAN_GO_CONFIG" > trojan-go-config.json
|
||||||
#打印配置文件内容
|
|
||||||
cat trojan-go-config.json
|
|
||||||
env:
|
env:
|
||||||
TROJAN_GO_CONFIG: ${{ secrets.TROJAN_GO_CONFIG }}
|
TROJAN_GO_CONFIG: ${{ secrets.TROJAN_GO_CONFIG }}
|
||||||
|
|
||||||
|
40
翻译更新日志.py
40
翻译更新日志.py
@ -1,29 +1,41 @@
|
|||||||
import requests
|
import requests
|
||||||
from datetime import datetime, timezone, timedelta
|
from datetime import datetime, timezone, timedelta
|
||||||
from deep_translator import GoogleTranslator
|
from deep_translator import GoogleTranslator
|
||||||
|
import logging
|
||||||
|
|
||||||
|
# 配置日志
|
||||||
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
# 设置 GitHub API URL
|
# 设置 GitHub API URL
|
||||||
repo = "coolsnowwolf/lede"
|
repo = "coolsnowwolf/lede"
|
||||||
url = f"https://api.github.com/repos/{repo}/commits"
|
url = f"https://api.github.com/repos/{repo}/commits"
|
||||||
|
logging.info(f"设置 GitHub API URL: {url}")
|
||||||
|
|
||||||
# 设置你所在的时区的 UTC 偏移量
|
# 设置你所在的时区的 UTC 偏移量
|
||||||
utc_offset = timedelta(hours=8)
|
utc_offset = timedelta(hours=8)
|
||||||
|
logging.info(f"设置时区偏移量: UTC+{utc_offset}")
|
||||||
|
|
||||||
# 尝试发送请求
|
# 尝试发送请求
|
||||||
try:
|
try:
|
||||||
|
logging.info("发送请求到 GitHub API...")
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
response.raise_for_status() # 如果响应不是200,将引发HTTPError异常
|
response.raise_for_status() # 如果响应不是200,将引发HTTPError异常
|
||||||
|
logging.info("请求成功,状态码: 200")
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
print(f"请求错误: {e}")
|
logging.error(f"请求错误: {e}")
|
||||||
else:
|
else:
|
||||||
commits = response.json()
|
commits = response.json()
|
||||||
|
logging.info("成功解析响应 JSON 数据")
|
||||||
|
|
||||||
# 获取最新提交的日期
|
# 获取最新提交的日期
|
||||||
latest_commit_date_utc = datetime.fromisoformat(commits[0]['commit']['committer']['date'].replace('Z', '+00:00'))
|
latest_commit_date_utc = datetime.fromisoformat(commits[0]['commit']['committer']['date'].replace('Z', '+00:00'))
|
||||||
latest_commit_date = latest_commit_date_utc.astimezone(timezone(utc_offset)).date()
|
latest_commit_date = latest_commit_date_utc.astimezone(timezone(utc_offset)).date()
|
||||||
|
logging.info(f"最新提交日期 (UTC): {latest_commit_date_utc}")
|
||||||
|
logging.info(f"最新提交日期 (本地时区): {latest_commit_date}")
|
||||||
|
|
||||||
# 初始化存储所有相关提交信息的字符串
|
# 初始化存储所有相关提交信息的字符串
|
||||||
all_commits_text = ""
|
all_commits_text = ""
|
||||||
|
logging.info("开始遍历提交记录,获取最新日期的提交信息")
|
||||||
|
|
||||||
for commit in commits:
|
for commit in commits:
|
||||||
commit_date_utc = datetime.fromisoformat(commit['commit']['committer']['date'].replace('Z', '+00:00'))
|
commit_date_utc = datetime.fromisoformat(commit['commit']['committer']['date'].replace('Z', '+00:00'))
|
||||||
@ -32,31 +44,31 @@ else:
|
|||||||
if commit_date == latest_commit_date:
|
if commit_date == latest_commit_date:
|
||||||
commit_message = commit['commit']['message']
|
commit_message = commit['commit']['message']
|
||||||
all_commits_text += commit_message + "\n" # 将每个提交信息添加到字符串中
|
all_commits_text += commit_message + "\n" # 将每个提交信息添加到字符串中
|
||||||
|
logging.info(f"找到匹配的提交日期: {commit_date},提交信息: {commit_message}")
|
||||||
|
|
||||||
# 创建一个Translator对象
|
# 创建一个 Translator 对象
|
||||||
#translator = Translator()
|
|
||||||
translator = GoogleTranslator(source='en', target='zh-CN')
|
translator = GoogleTranslator(source='en', target='zh-CN')
|
||||||
|
logging.info("创建 GoogleTranslator 对象")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 翻译合并后的提交信息文本
|
# 翻译合并后的提交信息文本
|
||||||
#translated_text = translator.translate(all_commits_text, src='en', dest='zh-CN')
|
logging.info("开始翻译提交信息文本")
|
||||||
#print(f"翻译后的提交信息:\n{translated_text.text}")
|
|
||||||
translated_text = translator.translate(all_commits_text)
|
translated_text = translator.translate(all_commits_text)
|
||||||
print(f"翻译后的提交信息:\n{translated_text}")
|
logging.info("翻译成功")
|
||||||
|
|
||||||
|
|
||||||
# 获取当前中国时间
|
# 获取当前中国时间
|
||||||
current_time = datetime.now(timezone(utc_offset))
|
current_time = datetime.now(timezone(utc_offset))
|
||||||
formatted_time = current_time.strftime("%Y年%m月%d日 %H点%M分")
|
formatted_time = current_time.strftime("%Y年%m月%d日 %H点%M分")
|
||||||
|
logging.info(f"当前时间 (本地): {formatted_time}")
|
||||||
# 将时间信息添加到翻译文本前面
|
|
||||||
# final_text = f"更新日期: {formatted_time}\n{translated_text.text}"
|
# 将时间信息添加到翻译文本前面
|
||||||
final_text = f"更新日期: {formatted_time}\n{translated_text}"
|
final_text = f"更新日期: {formatted_time}\n{translated_text}"
|
||||||
|
logging.info("格式化翻译文本")
|
||||||
|
|
||||||
|
|
||||||
# 输出翻译结果到文件
|
# 输出翻译结果到文件
|
||||||
with open('更新日志.txt', 'w', encoding='utf-8') as file:
|
with open('更新日志.txt', 'w', encoding='utf-8') as file:
|
||||||
file.write(final_text)
|
file.write(final_text)
|
||||||
|
logging.info("翻译结果已写入文件 '更新日志.txt'")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"翻译错误: {type(e).__name__}, {str(e)}")
|
logging.error(f"翻译错误: {type(e).__name__}, {str(e)}")
|
||||||
|
Loading…
Reference in New Issue
Block a user