move config to toml file
This commit is contained in:
parent
f899e6e13b
commit
44293e9323
2 changed files with 6 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -136,3 +136,4 @@ dmypy.json
|
||||||
index.html
|
index.html
|
||||||
|
|
||||||
config.conf
|
config.conf
|
||||||
|
config.toml
|
||||||
|
|
11
service.py
11
service.py
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import requests
|
import requests
|
||||||
import configparser
|
import tomlkit
|
||||||
import urllib3
|
import urllib3
|
||||||
urllib3.disable_warnings()
|
urllib3.disable_warnings()
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ class StatusPage:
|
||||||
|
|
||||||
|
|
||||||
def prettify(self, text):
|
def prettify(self, text):
|
||||||
for search, replace in self.config['prettify'].items():
|
for search, replace in self.config.get('prettify', {}).items():
|
||||||
text = text.replace(search.upper(), replace)
|
text = text.replace(search, replace)
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
@ -107,14 +107,13 @@ class StatusPage:
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.config = configparser.ConfigParser()
|
self.config = {}
|
||||||
self.config['icinga2_api'] = {
|
self.config['icinga2_api'] = {
|
||||||
'baseurl': 'https://localhost:5665',
|
'baseurl': 'https://localhost:5665',
|
||||||
'username': 'root',
|
'username': 'root',
|
||||||
'password': 'foobar'
|
'password': 'foobar'
|
||||||
}
|
}
|
||||||
with open('config.conf', 'r') as configfile:
|
self.config.update(tomlkit.loads(open('config.toml').read()))
|
||||||
self.config.read('config.conf')
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
page = StatusPage()
|
page = StatusPage()
|
||||||
|
|
Loading…
Reference in a new issue