__init__.py 751 B

12345678910111213141516171819202122232425262728293031
  1. from os import path, walk
  2. from googletrans import Translator
  3. from datetime import datetime, timezone, timedelta
  4. def write_md(f_dir, content):
  5. with open(f_dir, 'w',encoding="utf-8") as md:
  6. md.write(content)
  7. def read_line_md(f_dir):
  8. with open(f_dir, 'r',encoding="utf-8") as md:
  9. pre_content = md.readlines()
  10. return pre_content
  11. def gen_md_file_dirs(dir_):
  12. for root, dirs, files in walk(dir_):
  13. for f in files:
  14. if '.md' not in f:
  15. continue
  16. yield path.join(root, f)
  17. def translate(text):
  18. result = Translator().translate(text, dest='en')
  19. return result.text
  20. def get_now_time():
  21. return datetime.now(timezone(timedelta(hours=+8))).isoformat(timespec="seconds")