tools_load_config.py 804 B

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