conf.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @Contact : liuyuqi.gov@msn.cn
  5. @Time : 2023/07/11 20:18:28
  6. @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
  7. @Desc : read and write config.ini
  8. '''
  9. import os,sys,re,configparser
  10. file_path = "../conf/config.ini"
  11. def write():
  12. cf = configparser.ConfigParser()
  13. cf.read(file_path)
  14. if not cf.has_section("mail"):
  15. cf.add_section("mail")
  16. cf.set("mail", "host", "smtp.qq.com")
  17. cf.set("mail", "user", "xx@qq.com")
  18. cf.set("mail", "password", "12346")
  19. cf.set("mail", "sender", "xx@qq.com")
  20. cf.set("mail", "receviers", "xx@qq.com;xx@qq.com")
  21. if not cf.has_section("db"):
  22. cf.add_section("db")
  23. cf.set("db", "db_port", "3307")
  24. cf.write(open(file_path, "w"))
  25. if not cf.has_section("account"):
  26. cf.add_section("account")
  27. cf.set("account", "db_port", "3307")
  28. cf.write(open(file_path, "w"))
  29. def read():
  30. cf = configparser.ConfigParser()
  31. cf.read(file_path)
  32. opt_val = cf.get("db", "db_port")
  33. print(opt_val)
  34. kvs = cf.items("db")
  35. print(kvs)
  36. if __name__=='__main__':
  37. # read()
  38. import time
  39. # 打印时间戳,整形
  40. print(int(time.time()))