from configparser import ConfigParser from shutil import copy from requests import request ### Constants TRELLO_API_CARDS_URL = "https://api.trello.com/1/boards/{id}/cards" ### # 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 get_trello_cards(config: dict) -> list[dict]: """ Returns a list of every card in the Trello board, each a dict. """ url = TRELLO_API_CARDS_URL.format(id=config["Trello"]["boardid"]) query = { 'key': config["Trello"]["apikey"], 'token': config["Trello"]["apitoken"] } # Calling the API response = request( "GET", url, params=query ) # Making a list of cards with relevant information cards = [ { "id": card["id"], "name": card["name"], "lastActivity": card["dateLastActivity"], "memberIDs": card["idMembers"], "labels": [label["name"] for label in card["labels"]] } for card in response.json() ] return cards def main(): # Reading the config file config = read_config() # Getting the cards from Trello submissions = get_trello_cards(config) # Step 3: # For each card, compare to escalation rules to see if it's at the step # and escalation level it should be at. If not, flag it. # Step 4: # Generate reports for each person, showing their own cards. # Perhaps a "master report" with every card. # Step 5: # Send out the reports via email. if __name__ == "__main__": main()