提交 87d3be30 编写于 作者: ToTensor's avatar ToTensor

add code file

上级 94d2e73c
......@@ -9,14 +9,17 @@ from .ebook_get_request import get_chapter_content
def extract_code():
book_mapping_path = "data/book_mapping.json"
with open(book_mapping_path, "r") as f:
book_mapping = json.load(f)
# book_mapping_path = "data/book_mapping.json"
# with open(book_mapping_path, "r") as f:
# book_mapping = json.load(f)
book_mapping = {
"全程软件测试(第3版)": "825acb73c85c4c4bb9632afe858bc097",
}
for book_idx, book_name in enumerate(book_mapping.keys()):
if book_name == 'Python编程无师自通':
continue
book_dir_name = '{}.{}'.format(book_idx + 1, book_name)
book_dir = os.path.join('data/books', book_dir_name)
book_dir_name = book_name
book_dir = os.path.join('data', book_dir_name)
if not os.path.exists(book_dir):
os.mkdir(book_dir)
print(book_dir_name)
......@@ -73,10 +76,13 @@ def extract_code():
section_dir_list.append(section_dir)
for idx, section_content in enumerate(section_content_list):
if idx == 0:
save_dir = os.path.join(chapter_dir, 'text.html')
html_save_path = os.path.join(chapter_dir, 'text.html')
else:
save_dir = os.path.join(section_dir_list[idx - 1],
'text.html')
html_save_path = os.path.join(
section_dir_list[idx - 1], 'text.html')
with open(html_save_path, 'w', encoding='utf-8') as f:
f.write(section_content)
code_list = re.findall(r'<code>(.*?)</code>',
section_content, re.S)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册