settings.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import logging
  2. import sys
  3. import configparser
  4. import os
  5. from module.other.module_aes import Aes
  6. # ===============默认数据配置=====================
  7. config_name = "config.ini"
  8. if os.path.exists(config_name):
  9. with open(config_name) as f:
  10. pass
  11. config = configparser.ConfigParser()
  12. try:
  13. config.read(config_name, encoding="utf-8")
  14. except:
  15. config.read(config_name)
  16. # ===========用户自定义配置=======================
  17. custom_config_name = "custom_config.ini"
  18. if not os.path.exists(custom_config_name):
  19. with open(custom_config_name, 'w') as file:
  20. pass
  21. custom_config = configparser.ConfigParser()
  22. try:
  23. custom_config.read(custom_config_name, encoding="utf-8")
  24. except:
  25. custom_config.read(custom_config_name)
  26. def set_config(data_dict, section="basicSetup", _config_name="custom_config"):
  27. if _config_name == "config":
  28. for i, v in data_dict.items():
  29. config.set(section=section, option=i, value=v)
  30. try:
  31. config.write(open(config_name, 'w', encoding="ut-8"))
  32. except:
  33. config.write(open(config_name, 'w'))
  34. else:
  35. for i, v in data_dict.items():
  36. custom_config.set(section=section, option=i, value=v)
  37. try:
  38. custom_config.write(open(custom_config_name, 'w', encoding="ut-8"))
  39. except:
  40. custom_config.write(open(custom_config_name, 'w'))
  41. def get_config(section_items):
  42. __config_dict = {}
  43. try:
  44. for i, k in section_items:
  45. __config_dict[i] = k
  46. except:
  47. pass
  48. return __config_dict
  49. with open("key", "r") as f:
  50. Key = f.read()
  51. def set_key(authorization):
  52. global Authorization
  53. Authorization = authorization
  54. if authorization:
  55. authorization = Aes().get_key(authorization, SecretKey, SecretIv)
  56. with open("key", "w") as f:
  57. f.write(authorization)
  58. config_dict = get_config(config.items('basicSetup'))
  59. config_domain_dev_dict = get_config(config.items('domain_dev'))
  60. config_domain_prod_dict = get_config(config.items('domain_prod'))
  61. env = config_dict["env"]
  62. Version = config_dict["version"]
  63. Account = config_dict["account"]
  64. LastSelectPath = config_dict["last_select_path"]
  65. # ============用户自定义信息获取=============
  66. def get_custom_config(p_value, key, _custom_config_dict):
  67. if key in _custom_config_dict:
  68. if _custom_config_dict[key]:
  69. return _custom_config_dict[key]
  70. return p_value
  71. try:
  72. custom_config.add_section("basicSetup")
  73. except:
  74. pass
  75. custom_config_dict = get_config(custom_config.items('basicSetup'))
  76. is_test = "否"
  77. is_test = get_custom_config(is_test, "is_test", custom_config_dict)
  78. is_fall_dir = ""
  79. is_fall_dir = get_custom_config(is_fall_dir, "is_fall_dir", custom_config_dict)
  80. is_fall_dir = is_fall_dir.replace(",","")
  81. is_fall_dir = is_fall_dir.split(",")
  82. is_fall_dir = [x for x in is_fall_dir if x]
  83. if "已抠图" not in is_fall_dir:
  84. is_fall_dir.append("已抠图")
  85. is_fall_file = ""
  86. is_fall_file = get_custom_config(is_fall_file, "is_fall_file", custom_config_dict)
  87. is_fall_file = is_fall_file.replace(",","")
  88. is_fall_file = is_fall_file.split(",")
  89. is_fall_file = [x for x in is_fall_file if x]
  90. print("Version:",Version)
  91. if env == "dev":
  92. DOMAIN = config_domain_dev_dict["domain"]
  93. Host = config_domain_dev_dict["host"]
  94. Origin = config_domain_dev_dict["origin"]
  95. else:
  96. DOMAIN = config_domain_prod_dict["domain"]
  97. Host = config_domain_prod_dict["host"]
  98. Origin = config_domain_prod_dict["origin"]
  99. IsLogin = False
  100. SecretKey = "8E5EC2AC2191167DF9B753BA93A1E7B1"
  101. SecretIv = "0112030405060701"
  102. Authorization = Aes().get_authorization(Key, SecretKey, SecretIv)
  103. Headers = {
  104. "Authorization": Authorization,
  105. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
  106. "Origin": Origin,
  107. "Host": Host,
  108. "Content-Type": "application/json;charset=UTF-8"
  109. }