diff --git a/change_time campare.py b/change_time campare.py deleted file mode 100644 index 96cb91601..000000000 --- a/change_time campare.py +++ /dev/null @@ -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}") - - \ No newline at end of file diff --git a/git_time_get.py b/git_time_get.py index 69a4c3d83..f33889e32 100644 --- a/git_time_get.py +++ b/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 from rich.progress import track from git import Repo @@ -21,34 +107,8 @@ if __name__ == '__main__': 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() + print(f"{file_path} - {str(commit.committed_datetime).split(' ')[0]}") + @@ -56,29 +116,4 @@ if __name__ == '__main__': # 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 \ No newline at end of file + continue \ No newline at end of file