12345678910111213141516171819202122232425262728293031 |
- from os import path, walk
- from googletrans import Translator
- from datetime import datetime, timezone, timedelta
- def write_md(f_dir, content):
- with open(f_dir, 'w',encoding="utf-8") as md:
- md.write(content)
- def read_line_md(f_dir):
- with open(f_dir, 'r',encoding="utf-8") as md:
- pre_content = md.readlines()
- return pre_content
- def gen_md_file_dirs(dir_):
- for root, dirs, files in walk(dir_):
- for f in files:
- if '.md' not in f:
- continue
- yield path.join(root, f)
- def translate(text):
- result = Translator().translate(text, dest='en')
- return result.text
- def get_now_time():
- return datetime.now(timezone(timedelta(hours=+8))).isoformat(timespec="seconds")
|