handleDate.py 835 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. @author: Deepcold
  5. @file: handleDate.py
  6. @time: 2019/8/5 14:51
  7. """
  8. import os
  9. from ruamel import yaml
  10. from config import SOURCE_ROOT
  11. file_path = os.path.join(SOURCE_ROOT, "properties", "start_date.yaml")
  12. def get_date():
  13. # 将开始日期读进来
  14. with open(file_path, encoding='utf-8')as f:
  15. content = yaml.load(f.read(), Loader=yaml.Loader)
  16. return content
  17. def set_date(name, new_date):
  18. # 更改日期为当天日期
  19. content = get_date()
  20. with open(file_path, "w+", encoding='utf-8') as f:
  21. content[name] = new_date
  22. yaml.dump(content, f, default_flow_style=False,
  23. indent=2, allow_unicode=True, Dumper=yaml.RoundTripDumper)
  24. return content
  25. # if __name__ == '__main__':
  26. # set_date("wenshu_detail1", "2019-08-50")