From c42cf9cb1e32d6dfb3d862b047ee76fe67a027db Mon Sep 17 00:00:00 2001 From: Nikolaj Gade Date: Wed, 21 Aug 2024 13:46:45 +0200 Subject: [PATCH] :card_file_box: Trello Card fetcher --- config.ini.sample | 4 +++- main.py | 44 +++++++++++++++++++++++++++++++++++++++----- requirements.txt | 1 + 3 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 requirements.txt diff --git a/config.ini.sample b/config.ini.sample index 6a27365..4828ff5 100644 --- a/config.ini.sample +++ b/config.ini.sample @@ -1,5 +1,7 @@ [Trello] -TrelloAPIKey= +APIKey= +APIToken= +BoardID= [SMTP] Server= diff --git a/main.py b/main.py index 5a551d1..d4265fb 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,12 @@ 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): @@ -36,16 +43,43 @@ def read_config() -> dict: 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() - # Step 2: - # Get data from Trello API - # - Time each card has been in the step it's in - # - Escalation level - # - Who is assigned (as well as their email) + # 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 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ef487e0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +requests==2.32.3 \ No newline at end of file