-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/local/bin/python3 | ||
|
||
import os | ||
import glob | ||
import fileinput | ||
import linecache | ||
from functools import partial | ||
|
||
repo_dir = os.getcwd() | ||
source_dir = os.path.join(repo_dir, "source") | ||
all_md_path = os.path.join(repo_dir, "python-guide.pdf",) | ||
|
||
count = 0 | ||
|
||
with open(all_md_path, "w") as all_md: | ||
write = partial(print, file=all_md, end="") | ||
os.chdir(source_dir) | ||
|
||
for c_no in sorted(glob.glob("c*")): | ||
if c_no == "chapters" or c_no == "conf.py": | ||
continue | ||
|
||
# 读取并记下章节名 | ||
c_name = linecache.getline(os.path.join(source_dir, "chapters", f"{c_no.replace('c', 'p')}.rst"), 2) | ||
write(f"# {c_name}\n\n", file=all_md) | ||
|
||
# 读取每一节的内容 | ||
all_md_file = sorted(glob.glob(f"{source_dir}/{c_no}/*.md")) | ||
for line in fileinput.input(all_md_file): | ||
if "20200804124133" in line or "20200607174235" in line: | ||
continue | ||
|
||
if fileinput.isfirstline(): | ||
count += 1 | ||
if count%5 == 0: | ||
write("![](http://image.iswbm.com/20210606214719.png)", end="\n\n") | ||
|
||
if line.startswith("# "): | ||
line = line.replace("# ", "## ") | ||
elif line.startswith("## "): | ||
line = line.replace("## ", "### ") | ||
elif line.startswith("### "): | ||
line = line.replace("### ", "#### ") | ||
elif "gif" in line: | ||
line = line.replace("![]", "![该图为GIF,请前往 python.iswbm.com 浏览]") | ||
|
||
write(line) | ||
|