-
Notifications
You must be signed in to change notification settings - Fork 23
/
config.py
46 lines (35 loc) · 1.08 KB
/
config.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
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- encoding: utf-8 -*-
"""
@File : config.py
@Time : 2021/11/20 17:17
@Author : smy
@Email : smyyan@foxmail.com
@Software: PyCharm
"""
import configparser
def _print_config(config):
sections = config.sections()
print("sections:", sections)
for section in sections:
print("[%s]" % section)
for option in config.options(section):
print("\t%s=%s" % (option, config.get(section, option)))
class ReadConfig:
def __init__(self, filepath=None):
if filepath:
config_path = filepath
else:
config_path = "config/config.ini"
self.cf = configparser.ConfigParser()
self.cf.read(config_path, encoding='utf8')
_print_config(self.cf)
def get_bot_config(self, param):
value = self.cf.get("ByrBTBot", param, fallback=None)
return value
def get_transmission_config(self, param):
value = self.cf.get("Transmission", param, fallback=None)
return value
if __name__ == '__main__':
test = ReadConfig()
t = test.get_bot_config("byrbt-url")
print(t)