base_load_config.py 821 B

12345678910111213141516171819202122232425262728293031323334
  1. # -*- coding: utf-8 -*-
  2. '''
  3. 用于读取config.json
  4. 无需定时
  5. '''
  6. import json
  7. import os
  8. import sys
  9. sys.path.append(os.path.join(os.path.abspath(__file__).split('AutoInfo')[0] + 'AutoInfo'))
  10. def load_config():
  11. try:
  12. sys.path.append(os.path.join(os.getcwd().split('AutoInfo')[0], 'AutoInfo'))
  13. base_project = os.path.join(os.getcwd().split('AutoInfo')[0], 'AutoInfo')
  14. config_path = os.path.join(base_project, 'config.json')
  15. config_json = {}
  16. with open(config_path, 'r') as f:
  17. config_json = json.load(f)
  18. if not config_json:
  19. print('No config file found')
  20. exit(0)
  21. except Exception as e:
  22. print(e)
  23. exit(0)
  24. return config_json
  25. def get_base_path():
  26. return os.path.join(os.getcwd().split('auto')[0], 'auto')