1

Add newtrello

This commit is contained in:
Evan Pratten 2024-07-06 18:31:06 -04:00
parent d7038e45f2
commit 2c3f004512

62
scripts/newtrello Executable file
View File

@ -0,0 +1,62 @@
#! /usr/bin/env python3
import argparse
import sys
import logging
import subprocess
import requests
logger = logging.getLogger(__name__)
TRELLO_BOARD_ID = "tw3Cn3L6"
TRELLO_LIST_ID = "6348a3ce5208f505b61d29bf"
def main() -> int:
# Handle program arguments
ap = argparse.ArgumentParser(
prog="newtrello", description="Create a new to-do item in Trello"
)
ap.add_argument("title", help="Title of the new to-do item", nargs="+")
ap.add_argument(
"-v", "--verbose", help="Enable verbose logging", action="store_true"
)
args = ap.parse_args()
# Configure logging
logging.basicConfig(
level=logging.DEBUG if args.verbose else logging.INFO,
format="%(levelname)s: %(message)s",
)
# Read API credentials
trello_api_key = subprocess.check_output(
"op read -n 'op://ewconfig/cbnd5vv3germmc4korkxx3nsim/api key'", shell=True
).decode()
trello_api_token = subprocess.check_output(
"op read -n 'op://ewconfig/cbnd5vv3germmc4korkxx3nsim/credential'",
shell=True,
).decode()
# Read the title as a string
title = " ".join(args.title)
logger.info(f"Creating new to-do item: {title}")
# Create the card
response = requests.post(
f"https://api.trello.com/1/cards",
params={
"key": trello_api_key,
"token": trello_api_token,
"name": title,
"idList": TRELLO_LIST_ID,
"pos": "bottom",
},
)
response.raise_for_status()
logger.info("Created new card: %s", response.json()["shortUrl"])
return 0
if __name__ == "__main__":
sys.exit(main())