Update trello script for 1p
This commit is contained in:
parent
382edd2ea5
commit
be6e2c868b
@ -36,7 +36,7 @@ def main() -> int:
|
|||||||
print(f"Failed to connect to 1Password: {e}", file=sys.stderr)
|
print(f"Failed to connect to 1Password: {e}", file=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
# # Read API credentials
|
# Read API credentials
|
||||||
spotify_creds = op.item_get("rio7e6skp6bhkkcdo5w3kmabgq", vault="ewconfig")
|
spotify_creds = op.item_get("rio7e6skp6bhkkcdo5w3kmabgq", vault="ewconfig")
|
||||||
|
|
||||||
# Connect to Spotify
|
# Connect to Spotify
|
||||||
|
@ -2,16 +2,13 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
import subprocess
|
import pyonepassword
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
TRELLO_KEY = "fba640a85f15c91e93e6b3f88e59489c"
|
|
||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
# Handle program arguments
|
# Handle program arguments
|
||||||
ap = argparse.ArgumentParser(
|
ap = argparse.ArgumentParser(
|
||||||
@ -30,41 +27,31 @@ def main() -> int:
|
|||||||
format="%(levelname)s: %(message)s",
|
format="%(levelname)s: %(message)s",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Call `ewp-secrets` to obtain the Trello API token
|
# Connect to 1Password
|
||||||
secrets_proc = subprocess.run(
|
try:
|
||||||
[
|
op = pyonepassword.OP()
|
||||||
(Path(__file__).parent / "ewp-secrets").as_posix(),
|
except Exception as e:
|
||||||
"load",
|
print(f"Failed to connect to 1Password: {e}", file=sys.stderr)
|
||||||
"-n",
|
|
||||||
"ewpratten",
|
|
||||||
"-k",
|
|
||||||
"trello-api-token",
|
|
||||||
],
|
|
||||||
capture_output=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
# If the secret manager failed, exit
|
|
||||||
if secrets_proc.returncode != 0:
|
|
||||||
print("Failed to load Trello API token", file=sys.stderr)
|
|
||||||
print(
|
|
||||||
"Please run `ewp-secrets store -n ewpratten -k trello-api-token` to set a token",
|
|
||||||
file=sys.stderr,
|
|
||||||
)
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
# Extract the Trello API token
|
# Read API credentials
|
||||||
trello_api_token = secrets_proc.stdout.decode().strip()
|
trello_creds = op.item_get("cbnd5vv3germmc4korkxx3nsim", vault="ewconfig")
|
||||||
|
|
||||||
# Get all cards
|
# Get all cards
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
f"https://api.trello.com/1/boards/{args.board}/cards",
|
f"https://api.trello.com/1/boards/{args.board}/cards",
|
||||||
params=dict(key=TRELLO_KEY, token=trello_api_token),
|
params={
|
||||||
|
"key": trello_creds.first_field_by_label("api key").value,
|
||||||
|
"token": trello_creds.first_field_by_label("credential").value,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
cards = response.json()
|
cards = response.json()
|
||||||
|
|
||||||
# Find the card
|
# Find the card
|
||||||
card = next((card for card in cards if card["shortLink"] == args.card_short_link), None)
|
card = next(
|
||||||
|
(card for card in cards if card["shortLink"] == args.card_short_link), None
|
||||||
|
)
|
||||||
|
|
||||||
# If no card was found, fail
|
# If no card was found, fail
|
||||||
if not card:
|
if not card:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user