🗃️ Trello Card fetcher

This commit is contained in:
2024-08-21 13:46:45 +02:00
parent 2fd0163a34
commit c42cf9cb1e
3 changed files with 43 additions and 6 deletions

View File

@ -1,5 +1,7 @@
[Trello] [Trello]
TrelloAPIKey= APIKey=
APIToken=
BoardID=
[SMTP] [SMTP]
Server= Server=

44
main.py
View File

@ -1,5 +1,12 @@
from configparser import ConfigParser from configparser import ConfigParser
from shutil import copy 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 # TODO: Set up actual logging
def log(text: str): def log(text: str):
@ -36,16 +43,43 @@ def read_config() -> dict:
return 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(): def main():
# Reading the config file # Reading the config file
config = read_config() config = read_config()
# Step 2: # Getting the cards from Trello
# Get data from Trello API submissions = get_trello_cards(config)
# - Time each card has been in the step it's in
# - Escalation level
# - Who is assigned (as well as their email)
# Step 3: # Step 3:
# For each card, compare to escalation rules to see if it's at the step # For each card, compare to escalation rules to see if it's at the step

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
requests==2.32.3