mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-30 08:14:05 -06:00
delete my friend
This commit is contained in:
parent
9c07020288
commit
b89773004b
@ -1,74 +0,0 @@
|
|||||||
import os
|
|
||||||
from rich.progress import track
|
|
||||||
from git import Repo
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
|
||||||
content_path = r"C:\Users\83549\Documents\github_proj\content"
|
|
||||||
prefix_path = os.path.join(os.path.dirname(__file__), 'content')
|
|
||||||
|
|
||||||
file_path_list = []
|
|
||||||
date_list = []
|
|
||||||
|
|
||||||
for root, dirs, files in os.walk(content_path):
|
|
||||||
for file in files:
|
|
||||||
|
|
||||||
if '.' in root:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# ignore bug and continue running
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if file.endswith(".md"):
|
|
||||||
file_path = os.path.join(root, file)
|
|
||||||
repo = Repo(content_path)
|
|
||||||
file_path = os.path.relpath(file_path, repo.working_dir)
|
|
||||||
commit = repo.iter_commits(paths=file_path, max_count=1).__next__()
|
|
||||||
# print(f"{file_path} - {str(commit.committed_datetime).split(' ')[0]}")
|
|
||||||
|
|
||||||
file_path = file_path.replace('文学', 'literature')
|
|
||||||
file_path = file_path.replace('句子', 'sentence')
|
|
||||||
|
|
||||||
# check if path exists, no matter capital or not
|
|
||||||
|
|
||||||
file_path_list.append(os.path.join(prefix_path, file_path).lower())
|
|
||||||
date_list.append(str(commit.committed_datetime).split(' ')[0])
|
|
||||||
|
|
||||||
# print(file_path_list[-1])
|
|
||||||
|
|
||||||
|
|
||||||
for root, dirs, files in os.walk(prefix_path):
|
|
||||||
for file in files:
|
|
||||||
|
|
||||||
if '.' in root:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if file.endswith(".md"):
|
|
||||||
|
|
||||||
check_path = os.path.join(root, file)
|
|
||||||
check_path = check_path.lower()
|
|
||||||
|
|
||||||
if check_path in file_path_list:
|
|
||||||
index = file_path_list.index(check_path)
|
|
||||||
file_path = os.path.join(root, file)
|
|
||||||
date = date_list[index]
|
|
||||||
|
|
||||||
# open file and write date into it
|
|
||||||
f = open(file_path, 'r', encoding="utf-8")
|
|
||||||
|
|
||||||
lines = f.readlines()
|
|
||||||
for i in range(0, len(lines)):
|
|
||||||
if lines[i].startswith("date:") == True:
|
|
||||||
lines[i] = f"date: {date}\n"
|
|
||||||
|
|
||||||
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
f = open(file_path, 'w', encoding="utf-8")
|
|
||||||
f.writelines(lines)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
print(f"{file_path} - {date}")
|
|
||||||
|
|
||||||
|
|
||||||
139
git_time_get.py
139
git_time_get.py
@ -1,3 +1,89 @@
|
|||||||
|
# import os
|
||||||
|
# from rich.progress import track
|
||||||
|
# from git import Repo
|
||||||
|
|
||||||
|
# if __name__ == '__main__':
|
||||||
|
|
||||||
|
# content_path = os.path.join(os.path.dirname(__file__), 'content')
|
||||||
|
|
||||||
|
# for root, dirs, files in os.walk(content_path):
|
||||||
|
# for file in files:
|
||||||
|
|
||||||
|
# if '.' in root:
|
||||||
|
# continue
|
||||||
|
|
||||||
|
# # ignore bug and continue running
|
||||||
|
|
||||||
|
# try:
|
||||||
|
|
||||||
|
# if file.endswith(".md"):
|
||||||
|
# file_path = os.path.join(root, file)
|
||||||
|
# repo = Repo(content_path)
|
||||||
|
# file_path = os.path.relpath(file_path, repo.working_dir)
|
||||||
|
# commit = repo.iter_commits(paths=file_path, max_count=1).__next__()
|
||||||
|
# # print(f"{file_path} - {str(commit.committed_datetime).split(' ')[0]}")
|
||||||
|
|
||||||
|
# flag = False
|
||||||
|
|
||||||
|
# # open file and write date into it
|
||||||
|
# f = open(os.path.join(root, file), 'r', encoding="utf-8")
|
||||||
|
|
||||||
|
# lines = f.readlines()
|
||||||
|
# if lines[0].startswith("---"):
|
||||||
|
# for i in range(1, len(lines)):
|
||||||
|
# if lines[i] == "---\n" and lines[i-1].startswith("date") == False:
|
||||||
|
# flag = True
|
||||||
|
# lines.insert(i, f"date: {str(commit.committed_datetime).split(' ')[0]}\n")
|
||||||
|
# break
|
||||||
|
# if lines[i] == "---\n" and lines[i-1].startswith("date") == True:
|
||||||
|
# break
|
||||||
|
|
||||||
|
# f.close()
|
||||||
|
|
||||||
|
|
||||||
|
# if flag == True:
|
||||||
|
|
||||||
|
# f = open(os.path.join(root, file), 'w', encoding="utf-8")
|
||||||
|
|
||||||
|
# f.writelines(lines)
|
||||||
|
# print(f"{file_path} - {str(commit.committed_datetime).split(' ')[0]}")
|
||||||
|
|
||||||
|
# f.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# except:
|
||||||
|
# # output error message
|
||||||
|
# print(f"Error: {file_path}")
|
||||||
|
# pass
|
||||||
|
# continue
|
||||||
|
|
||||||
|
# print()
|
||||||
|
# print('--------------------------------------')
|
||||||
|
# print
|
||||||
|
|
||||||
|
# try:
|
||||||
|
|
||||||
|
# for root, dirs, files in os.walk(content_path):
|
||||||
|
# for file in files:
|
||||||
|
|
||||||
|
# if "." in root:
|
||||||
|
# continue
|
||||||
|
|
||||||
|
# if '.md' in file:
|
||||||
|
|
||||||
|
# with open(os.path.join(root, file), 'r', encoding='utf-8') as f:
|
||||||
|
# lines = f.readlines()
|
||||||
|
# if lines[0].startswith("---") == False:
|
||||||
|
# print(f"{os.path.join(root, file)}")
|
||||||
|
|
||||||
|
# f.close()
|
||||||
|
|
||||||
|
# except:
|
||||||
|
# print(f"Error: {os.path.join(root, file)}")
|
||||||
|
# pass
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from rich.progress import track
|
from rich.progress import track
|
||||||
from git import Repo
|
from git import Repo
|
||||||
@ -21,34 +107,8 @@ if __name__ == '__main__':
|
|||||||
repo = Repo(content_path)
|
repo = Repo(content_path)
|
||||||
file_path = os.path.relpath(file_path, repo.working_dir)
|
file_path = os.path.relpath(file_path, repo.working_dir)
|
||||||
commit = repo.iter_commits(paths=file_path, max_count=1).__next__()
|
commit = repo.iter_commits(paths=file_path, max_count=1).__next__()
|
||||||
# print(f"{file_path} - {str(commit.committed_datetime).split(' ')[0]}")
|
print(f"{file_path} - {str(commit.committed_datetime).split(' ')[0]}")
|
||||||
|
|
||||||
flag = False
|
|
||||||
|
|
||||||
# open file and write date into it
|
|
||||||
f = open(os.path.join(root, file), 'r', encoding="utf-8")
|
|
||||||
|
|
||||||
lines = f.readlines()
|
|
||||||
if lines[0].startswith("---"):
|
|
||||||
for i in range(1, len(lines)):
|
|
||||||
if lines[i] == "---\n" and lines[i-1].startswith("date") == False:
|
|
||||||
flag = True
|
|
||||||
lines.insert(i, f"date: {str(commit.committed_datetime).split(' ')[0]}\n")
|
|
||||||
break
|
|
||||||
if lines[i] == "---\n" and lines[i-1].startswith("date") == True:
|
|
||||||
break
|
|
||||||
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
|
|
||||||
if flag == True:
|
|
||||||
|
|
||||||
f = open(os.path.join(root, file), 'w', encoding="utf-8")
|
|
||||||
|
|
||||||
f.writelines(lines)
|
|
||||||
print(f"{file_path} - {str(commit.committed_datetime).split(' ')[0]}")
|
|
||||||
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -57,28 +117,3 @@ if __name__ == '__main__':
|
|||||||
print(f"Error: {file_path}")
|
print(f"Error: {file_path}")
|
||||||
pass
|
pass
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print()
|
|
||||||
print('--------------------------------------')
|
|
||||||
print
|
|
||||||
|
|
||||||
try:
|
|
||||||
|
|
||||||
for root, dirs, files in os.walk(content_path):
|
|
||||||
for file in files:
|
|
||||||
|
|
||||||
if "." in root:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if '.md' in file:
|
|
||||||
|
|
||||||
with open(os.path.join(root, file), 'r', encoding='utf-8') as f:
|
|
||||||
lines = f.readlines()
|
|
||||||
if lines[0].startswith("---") == False:
|
|
||||||
print(f"{os.path.join(root, file)}")
|
|
||||||
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
except:
|
|
||||||
print(f"Error: {os.path.join(root, file)}")
|
|
||||||
pass
|
|
||||||
Loading…
Reference in New Issue
Block a user