From 44293e9323edb37e4bad9d4df2fd6fb462739760 Mon Sep 17 00:00:00 2001 From: Sophie Schiller Date: Sat, 10 Apr 2021 16:05:09 +0200 Subject: [PATCH] move config to toml file --- .gitignore | 1 + service.py | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 9077528..e1ff618 100644 --- a/.gitignore +++ b/.gitignore @@ -136,3 +136,4 @@ dmypy.json index.html config.conf +config.toml diff --git a/service.py b/service.py index 587d2f5..b66b2e4 100755 --- a/service.py +++ b/service.py @@ -2,7 +2,7 @@ import json import requests -import configparser +import tomlkit import urllib3 urllib3.disable_warnings() @@ -32,8 +32,8 @@ class StatusPage: def prettify(self, text): - for search, replace in self.config['prettify'].items(): - text = text.replace(search.upper(), replace) + for search, replace in self.config.get('prettify', {}).items(): + text = text.replace(search, replace) return text @@ -107,14 +107,13 @@ class StatusPage: def __init__(self): - self.config = configparser.ConfigParser() + self.config = {} self.config['icinga2_api'] = { 'baseurl': 'https://localhost:5665', 'username': 'root', 'password': 'foobar' } - with open('config.conf', 'r') as configfile: - self.config.read('config.conf') + self.config.update(tomlkit.loads(open('config.toml').read())) if __name__ == "__main__": page = StatusPage()