From 99d0c74762bac35f630109b09feb4df6db31b39b Mon Sep 17 00:00:00 2001
From: LetMeFly666 <814114971@qq.com>
Date: Tue, 11 Jun 2024 22:22:38 +0800
Subject: [PATCH] chore: being v2.7 - no history on branch website
---
.../Other-English-LearningNotes-SomeWords.md | 3 +
archiveHistory.py | 63 +++++++++++++++++++
2 files changed, 66 insertions(+)
create mode 100644 archiveHistory.py
diff --git a/Solutions/Other-English-LearningNotes-SomeWords.md b/Solutions/Other-English-LearningNotes-SomeWords.md
index d5b02ebbdf5..ff26fb1fee9 100644
--- a/Solutions/Other-English-LearningNotes-SomeWords.md
+++ b/Solutions/Other-English-LearningNotes-SomeWords.md
@@ -253,6 +253,9 @@ tags: [其他, 知识, 英语, Notes]
|mathematician|n. 数学家|
|inn|n. 客栈,(乡村可夜宿的)小酒店
v. 住旅馆|
|flux|n. 不断的变动,不停的变化,通量,流动|
+|||
+|maize|n. 玉米|
+|vine|n. 藤,藤蔓,藤本植物|
扇贝音频测试
diff --git a/archiveHistory.py b/archiveHistory.py
new file mode 100644
index 00000000000..0c375938812
--- /dev/null
+++ b/archiveHistory.py
@@ -0,0 +1,63 @@
+'''
+Author: LetMeFly
+Date: 2024-06-11 21:59:50
+LastEditors: LetMeFly
+LastEditTime: 2024-06-11 22:21:22
+'''
+"""
+写一个Python脚本,实现以下功能:
+在一个Git仓库中,将每次commit打包成Zip文件。
+文件命名格式为对应commit的{日期}{时间}{commitHash}.zip,例如20240622-220603-54a2e7fe41081489e8913436daa7bee5ae878d26.zip
+"""
+import os
+import zipfile
+import git
+from datetime import datetime
+import shutil
+
+def zip_commit(repo_path, commit: git.Commit):
+ # 提取 commit 日期和时间
+ print(commit.message)
+ commit_datetime = datetime.fromtimestamp(commit.committed_date)
+ date_str = commit_datetime.strftime('%Y%m%d')
+ time_str = commit_datetime.strftime('%H%M%S')
+
+ # 构造 zip 文件名
+ zip_filename = f"archived/{date_str}-{time_str}-{commit.hexsha}.zip"
+
+ # 创建一个临时目录来存储这个 commit 的文件
+ temp_dir = f"temp"
+ os.makedirs(temp_dir, exist_ok=True)
+
+ # 导出 commit 的文件
+ repo.git.checkout(commit)
+ for item in repo.tree().traverse():
+ if item.type == 'blob': # 确保这是一个文件而不是一个子目录
+ item_path = os.path.join(repo_path, item.path)
+ os.makedirs(os.path.dirname(os.path.join(temp_dir, item.path)), exist_ok=True)
+ with open(item_path, 'rb') as fsrc, open(os.path.join(temp_dir, item.path), 'wb') as fdst:
+ fdst.write(fsrc.read())
+
+ # 打包成 zip 文件
+ with zipfile.ZipFile(zip_filename, 'w') as zipf:
+ for root, _, files in os.walk(temp_dir):
+ for file in files:
+ zipf.write(os.path.join(root, file), os.path.relpath(os.path.join(root, file), temp_dir))
+
+ # 清理临时目录
+ shutil.rmtree(temp_dir)
+
+if __name__ == "__main__":
+ # 指定你的 Git 仓库路径
+ repo_path = 'repo'
+ os.makedirs('archived', exist_ok=True)
+
+ # 打开仓库
+ repo = git.Repo(repo_path)
+
+ # 遍历所有的 commit
+ for commit in repo.iter_commits():
+ zip_commit(repo_path, commit)
+
+ # 切换回默认分支(例如 'main' 或 'master')
+ repo.git.checkout('master')