config.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from dotenv import load_dotenv
  2. import os
  3. import sys
  4. from logger import logging
  5. import uuid
  6. class Config:
  7. def __init__(self):
  8. # 获取应用程序的根目录路径
  9. if getattr(sys, "frozen", False):
  10. # 如果是打包后的可执行文件
  11. application_path = os.path.dirname(sys.executable)
  12. else:
  13. # 如果是开发环境
  14. application_path = os.path.dirname(os.path.abspath(__file__))
  15. self.auth_token = str(uuid.uuid4()).replace('-', '')
  16. def get_temp_mail(self):
  17. # 返回临时邮箱地址
  18. return getattr(self, 'temp_mail', None)
  19. def set_temp_mail(self, mail):
  20. self.temp_mail = mail
  21. def get_auth_token(self):
  22. return self.auth_token
  23. def check_is_valid(self, str):
  24. return len(str.strip()) > 0
  25. def print_config(self):
  26. temp_mail = self.get_temp_mail()
  27. if temp_mail:
  28. logging.info(f"\033[32m临时邮箱: {temp_mail}\033[0m")
  29. # 使用示例
  30. if __name__ == "__main__":
  31. try:
  32. config = Config()
  33. print("配置初始化成功!")
  34. config.get_temp_mail()
  35. except Exception as e:
  36. print(f"错误: {e}")