-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
34 lines (28 loc) · 912 Bytes
/
config.py
File metadata and controls
34 lines (28 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import yaml
import os
import sys
config_path = os.path.join(os.path.dirname(__file__), 'configs.yaml')
# 读取配置文件
try:
with open(config_path, 'r', encoding='utf-8') as file:
config = yaml.safe_load(file)
except FileNotFoundError:
print(f"Error: The configuration file {config_path} does not exist.")
sys.exit(1)
except yaml.YAMLError as e:
print(f"Error parsing YAML file: {e}")
sys.exit(1)
# 运营商常量
TELECOM = "telecom" # 电信
CMCC = "cmcc" # 移动
UNICOM = "unicom" # 联通
# 获取配置
user_account = config['user_account']
operator = config['operator']
user_password = config['user_password']
# 验证运营商是否合法
valid_operators = [TELECOM, CMCC, UNICOM]
if operator not in valid_operators:
print(f"Error: Invalid operator '{operator}'. Must be one of {valid_operators}.")
sys.exit(1)
print("Configuration loaded successfully.")