-
Notifications
You must be signed in to change notification settings - Fork 1
/
conf.py
33 lines (28 loc) · 823 Bytes
/
conf.py
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
# -*- coding: utf-8 -*-
# Author: coolrc <[email protected]>
# date: 2021/7/11
"""读取配置文件"""
from validit import Template, TemplateDict, Optional, ValidateFromYAML
filepath = 'config.yaml'
template = TemplateDict(
mail=TemplateDict(
email=Template(str),
password=Template(str),
host=Template(str)
),
http=TemplateDict(
port=Template(int)
),
token=Template(str)
)
with open(filepath, 'r') as file:
# load and validate data from the file
valid = ValidateFromYAML(template, file)
config = valid.data
if valid.errors: # if one or more errors found
print(valid.errors) # print errors to console
exit(1) # exit the script with exit code 1
# else: # if data matches the template
# print(valid.data)
if __name__ == '__main__':
pass