⚙️ Reads config file
This commit is contained in:
46
main.py
46
main.py
@ -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():
|
||||
# Step 1:
|
||||
# Create an config file from the sample file if there is none,
|
||||
# then return.
|
||||
# Read config file if it already existed.
|
||||
# Reading the config file
|
||||
config = read_config()
|
||||
|
||||
# Step 2:
|
||||
# Get data from Trello API
|
||||
@ -20,7 +57,6 @@ def main():
|
||||
|
||||
# Step 5:
|
||||
# Send out the reports via email.
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user