sunetdrive/templates/scriptreceiver/ini2json.py

19 lines
506 B
Python
Raw Normal View History

2023-02-13 09:44:56 +00:00
#!/usr/bin/env python3
import configparser
import sys
import json
config = configparser.ConfigParser()
str_conf = ""
for line in sys.stdin.read().splitlines(keepends=True):
if not (line.startswith("-") or line.startswith("#")):
str_conf += line
config.read_string(str_conf)
dictionary = {}
for section in config.sections():
dictionary[section] = {}
for option in config.options(section):
dictionary[section][option] = config.get(section, option)
print(json.dumps(dictionary))