1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
import subprocess import datetime import time
repo_directory = r"M:\blog_hexo"
try: subprocess.run(f"cd /d {repo_directory} && git status", shell=True, check=True, stdout=subprocess.PIPE)
except subprocess.CalledProcessError as e: print("切换目录时出现错误:", e) exit(1)
current_datetime = datetime.datetime.now() formatted_datetime = current_datetime.strftime("%Y-%m-%d_%H%M%S")
with open(f"{repo_directory}/log.txt", "w") as fw: fw.write(formatted_datetime + '\n')
try: subprocess.run(f"cd /d {repo_directory} && yuque-hexo sync", shell=True, check=True)
subprocess.run(f"cd /d {repo_directory} && git add .", shell=True, check=True)
subprocess.run(f"cd /d {repo_directory} && git commit -m '{formatted_datetime}'", shell=True, check=True)
subprocess.run(f"cd /d {repo_directory} && git push", shell=True, check=True)
print("成功提交到GitHub")
except subprocess.CalledProcessError as e: print("=" * 80) print("执行Git命令时出现错误:", e) exit(1)
|