#! /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())