Files
yihong0618 3fc048652a fix
2023-07-13 16:39:41 +08:00

26 lines
720 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import re
from kindle_download_helper.config import GITHUB_README_COMMENTS
def replace_readme_comments(file_name, comment_str, comments_name):
with open(file_name, "r+", encoding="UTF-8") as f:
text = f.read()
# regrex sub from github readme comments
text = re.sub(
GITHUB_README_COMMENTS.format(name=comments_name),
r"\1{}\n\3".format(comment_str),
text,
flags=re.DOTALL,
)
f.seek(0)
f.write(text)
f.truncate()
def trim_title_suffix(title):
new_title = re.sub(r"([^]+?|【[^】]+】?)", "", title)
for ch in '\/:*?"<>|':
new_title = new_title.replace(ch, "-")
return new_title