config.py 1018 B

1234567891011121314151617181920212223242526272829303132333435
  1. # !/usr/bin/python
  2. # -*- encoding: utf-8 -*-
  3. """
  4. @Time : 2025/07/10 14:40
  5. @Author :
  6. @File : config.py
  7. @Software: VScode
  8. @Desc : None
  9. """
  10. from configparser import ConfigParser
  11. class ConfigHandler:
  12. def __init__(self, config_file=""):
  13. self.config = ConfigParser()
  14. self.config.read(config_file, encoding='utf-8')
  15. def get(self, section, option, default=None):
  16. try:
  17. if section == "before":
  18. option = f"online_{option}" if bool(self.config.get("general", "is_online")) else f"inline_{option}"
  19. value = self.config.get(section, option)
  20. else:
  21. value = self.config.get(section, option)
  22. if "#" in value:
  23. value = value.split('#')[0].strip()
  24. except Exception as err:
  25. value = default
  26. return value
  27. def getboolean(self, section, option):
  28. return self.config.getboolean(section, option)
  29. config_handler = ConfigHandler("./config/config.ini")