You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kmftools/bookscraper/scraper/utils.py

23 lines
476 B

import os
# scraper/utils.py
def load_replacements(path):
repl = {}
if not path or not os.path.exists(path):
return repl
with open(path, encoding="utf-8") as f:
for line in f:
if "=>" in line:
k, v = line.strip().split("=>", 1)
repl[k.strip()] = v.strip()
return repl
def clean_text(text, repl_dict):
for src, tgt in repl_dict.items():
text = text.replace(src, tgt)
return text