diff --git a/.gitignore b/.gitignore index 778cafa1186c79a1047cbc1e3f9da4dc440bbdb3..df302c7fa53d9034cffdd26ae7194d1df54ceeee 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ auto_gen_leetcode_tem.py leetcode_helper.py lanqiao_helper.py lanqiao_template.md +test.html ./src/__pycache__/*.pyc \ No newline at end of file diff --git a/leetcode_helper.py b/leetcode_helper.py index 063afa0e7405b64fd63bd1d18609e96d7926c499..e4726eb387271e5d80f1ba2c80e3a41ed60b5d0e 100644 --- a/leetcode_helper.py +++ b/leetcode_helper.py @@ -1,4 +1,5 @@ import os +import re import shutil def leetcode_helper(): data_dir = 'data/3.算法高阶/1.leetcode' @@ -75,4 +76,32 @@ def leetcode_helper_delete_md(): if leetcode_solution_md_data == template: os.remove(solution_md_path) -leetcode_helper_delete_md() \ No newline at end of file +def leetcode_helper_update_md(): + data_dir = 'data/3.算法高阶/1.leetcode' + dirs_ = os.listdir(data_dir) + dirs = [] + for dir in dirs_: + dir = os.path.join(data_dir, dir) + if os.path.isdir(dir): + dirs.append(dir) + for dir in dirs: + assert os.path.isdir(dir) + exercises_id = dir.split('/')[-1].split('_')[0] + title = dir.split('/')[-1].split('_')[1] + if 0 <= int(exercises_id) and int(exercises_id) < 52: + solution_md_path = os.path.join(dir, 'solution.md') + desc_html_path = os.path.join(dir, 'desc.html') + with open(solution_md_path, 'r', encoding='utf-8') as f: + solution_md_data = f.read() + with open(desc_html_path, 'r', encoding='utf-8') as f: + desc_html_data = f.read() + content = re.findall('# .*?\n(.*?)\n## aop'.format(title), solution_md_data, re.DOTALL)[0] + new_content = desc_html_data + "\n

{}

".format(content) + # print(solution_md_path) + solution_md_data = solution_md_data.replace(content, new_content) + # print(solution_md_data) + with open(solution_md_path, 'w', encoding='utf-8') as f: + f.write(solution_md_data) + + +leetcode_helper_update_md() \ No newline at end of file