⚙️ Reads config file

This commit is contained in:
2024-08-21 13:01:47 +02:00
parent 9b5bed321c
commit 2fd0163a34

46
main.py
View File

@ -1,8 +1,45 @@
from configparser import ConfigParser
from shutil import copy
# TODO: Set up actual logging
def log(text: str):
print(text)
def read_config() -> dict:
"""
Returns the contents of config.ini as a a dict, assuming it exists and has
no empty fields.
"""
config = ConfigParser()
# Reads the file and checks if it exists
if config.read('config.ini') == []:
copy("config.ini.sample","config.ini")
log("Creating config.ini file")
exit()
# Creates the dict and removes the "DEFAULTS" section
config_dict = {
key: dict(value) for key,value in dict(config).items()
if key != "DEFAULT"
}
# Checks if every field is filled out
all_filled_out = all(
all(v2 != '' for _,v2 in v1.items())
for _,v1 in config_dict.items()
)
if not all_filled_out:
log("Empty fields in config.ini")
exit()
return config_dict
def main(): def main():
# Step 1: # Reading the config file
# Create an config file from the sample file if there is none, config = read_config()
# then return.
# Read config file if it already existed.
# Step 2: # Step 2:
# Get data from Trello API # Get data from Trello API
@ -20,7 +57,6 @@ def main():
# Step 5: # Step 5:
# Send out the reports via email. # Send out the reports via email.
pass
if __name__ == "__main__": if __name__ == "__main__":