提交 7b8dc6ae 编写于 作者: 每日一练社区's avatar 每日一练社区

add update md code

上级 8b6d46b8
......@@ -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
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<p>{}</p>".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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册