Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Trello - Delete cards #2299

Merged
merged 1 commit into from
Oct 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
350 changes: 350 additions & 0 deletions Trello/Trello_Delete_Cards.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,350 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "steady-basin",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"<img width=\"10%\" alt=\"Naas\" src=\"https://landen.imgix.net/jtci2pxwjczr/assets/5ice39g4.png?w=160\"/>"
]
},
{
"cell_type": "markdown",
"id": "undefined-victory",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"# Trello - Delete cards\n",
"<a href=\"https://app.naas.ai/user-redirect/naas/downloader?url=https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/Trello/Trello_Get_Lists_on_a_Board.ipynb\" target=\"_parent\"><img src=\"https://naasai-public.s3.eu-west-3.amazonaws.com/Open_in_Naas_Lab.svg\"/></a><br><br><a href=\"https://bit.ly/3JyWIk6\">Give Feedback</a> | <a href=\"https://github.com/jupyter-naas/awesome-notebooks/issues/new?assignees=&labels=bug&template=bug_report.md&title=Trello+-+Get+Lists+on+a+Board:+Error+short+description\">Bug report</a>"
]
},
{
"cell_type": "markdown",
"id": "08e617eb-f6d2-47be-a1fc-56c1322c065b",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Tags:** #trello #project #delete #snippet #operations #lists #board\n"
]
},
{
"cell_type": "markdown",
"id": "naas-author",
"metadata": {
"papermill": {},
"tags": [
"naas"
]
},
"source": [
"**Author:** [Benjamin Filly](https://www.linkedin.com/in/benjamin-filly-05427727a/)\n"
]
},
{
"cell_type": "markdown",
"id": "ea908824-36c0-4c64-8e3b-8169ed95ea56",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**Last update:** 2023-07-14 (Created: 2023-07-14)"
]
},
{
"cell_type": "markdown",
"id": "naas-description",
"metadata": {
"papermill": {},
"tags": [
"description"
]
},
"source": [
"**Description:** This notebook shows how to automatically remove a card from Trello using the API. "
]
},
{
"cell_type": "markdown",
"id": "575e5c78-17a8-48b6-9244-fc1c0d996f12",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"**References:**\n",
"- [Trello - Delete a card](https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-delete)"
]
},
{
"cell_type": "markdown",
"id": "input_cell",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Input"
]
},
{
"cell_type": "markdown",
"id": "import_cell",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Import libraries"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "supreme-westminster",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-12T17:31:46.341566Z",
"iopub.status.busy": "2023-10-12T17:31:46.341377Z",
"iopub.status.idle": "2023-10-12T17:31:49.763338Z",
"shell.execute_reply": "2023-10-12T17:31:49.762559Z",
"shell.execute_reply.started": "2023-10-12T17:31:46.341516Z"
},
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"import requests\n",
"import naas"
]
},
{
"cell_type": "markdown",
"id": "exotic-academy",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Setup variables"
]
},
{
"cell_type": "markdown",
"id": "reduced-tourist",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"- `card_id`: The unique identifier of the Trello card you want to delete.\n",
"- `board_id`: The unique identifier of the Trello board you want to work with.\n",
"- `api_key`: Your Trello API key. [Get your API key here](https://github.com/Benjifilly/My_notebooks/wiki/How-to-obtain-an-API-key-for-Trello)\n",
"- `force_update`: Parameters to enforce the token update"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "tender-albany",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-12T17:31:49.765026Z",
"iopub.status.busy": "2023-10-12T17:31:49.764502Z",
"iopub.status.idle": "2023-10-12T17:31:49.934440Z",
"shell.execute_reply": "2023-10-12T17:31:49.933810Z",
"shell.execute_reply.started": "2023-10-12T17:31:49.764928Z"
},
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"card_id = \"zfKRjpgu\" # Replace this with the ID of the card you want to delete\n",
"board_id = \"TWbaquXE\" # Example: \"https://trello.com/b/TWbaquXE/ultimate-to-do-list\"\n",
"\n",
"api_key = naas.secret.get(\"TRELLO_API_KEY\") or \"YOUR_TRELLO_API_KEY\"\n",
"force_update = False"
]
},
{
"cell_type": "markdown",
"id": "model_cell",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Model"
]
},
{
"cell_type": "markdown",
"id": "0f97f2a0-976d-42c1-b9d4-3b6597ab8453",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Get your token\n",
"Your Trello token will be stored on naas secret name: \"TRELLO_TOKEN\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "96e73242-c286-4413-8d69-825ad7391584",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-12T17:31:49.937426Z",
"iopub.status.busy": "2023-10-12T17:31:49.937243Z",
"iopub.status.idle": "2023-10-12T17:31:50.106578Z",
"shell.execute_reply": "2023-10-12T17:31:50.105905Z",
"shell.execute_reply.started": "2023-10-12T17:31:49.937406Z"
},
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"def get_token(api_key, force_update):\n",
" token = naas.secret.get(\"TRELLO_TOKEN\")\n",
" if not token or force_update:\n",
" url = f\"https://trello.com/1/authorize?expiration=never&scope=read,write,account&response_type=token&key={api_key}\"\n",
" print(f\"🔗 Click on the URL to get your token: {url}\")\n",
" print(\"✅ On the authorization page, click on 'Authorize' button at the bottom of the page to proceed.\")\n",
" print(\"💾 Copy/Paste the token in red in the input case below\")\n",
" token = input(\"-> Enter your token here:\")\n",
" naas.secret.add(\"TRELLO_TOKEN\", token)\n",
" return token\n",
"\n",
"token = get_token(api_key, force_update)"
]
},
{
"cell_type": "markdown",
"id": "c97e69d0-8851-4139-ba3b-339753fde780",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Deleting cards\n",
"Make a GET request to the Trello API to delete the target card"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "6ad17a5c-689b-4c43-9630-3765e3d0e239",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-12T17:31:50.108627Z",
"iopub.status.busy": "2023-10-12T17:31:50.108347Z",
"iopub.status.idle": "2023-10-12T17:31:50.835701Z",
"shell.execute_reply": "2023-10-12T17:31:50.835033Z",
"shell.execute_reply.started": "2023-10-12T17:31:50.108573Z"
},
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"delete_url = f\"https://api.trello.com/1/cards/{card_id}?key={api_key}&token={token}\" # Construct the URL to delete the card\n",
"response = requests.delete(delete_url) # Send the DELETE request"
]
},
{
"cell_type": "markdown",
"id": "output_cell",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"## Output"
]
},
{
"cell_type": "markdown",
"id": "display_cell",
"metadata": {
"papermill": {},
"tags": []
},
"source": [
"### Display result"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "73bd6ede-4b47-465f-8c71-3d3caa3e7dce",
"metadata": {
"execution": {
"iopub.execute_input": "2023-10-12T17:31:50.837075Z",
"iopub.status.busy": "2023-10-12T17:31:50.836828Z",
"iopub.status.idle": "2023-10-12T17:31:50.841345Z",
"shell.execute_reply": "2023-10-12T17:31:50.840687Z",
"shell.execute_reply.started": "2023-10-12T17:31:50.837045Z"
},
"papermill": {},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Card successfully deleted ✅\n"
]
}
],
"source": [
"if response.status_code == 200:\n",
" print(\"Card successfully deleted ✅\")\n",
"else:\n",
" print(\"❌ Failed to delete the card. Status code:\", response.status_code)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
},
"naas": {
"notebook_id": "e0c37b0b9b71eef4ba954737ebcf7889a1961540390e8d61dc9665188cdb9cc1",
"notebook_path": "Trello/Trello_Get_Lists_on_a_Board.ipynb"
},
"papermill": {
"default_parameters": {},
"environment_variables": {},
"parameters": {},
"version": "2.3.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading