mirror of
https://github.com/chenasraf/nextcloud-deck-tools.git
synced 2026-05-17 17:28:07 +00:00
83 lines
2.1 KiB
Python
83 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
from __future__ import annotations
|
|
import argparse
|
|
import json
|
|
import sys
|
|
import requests
|
|
|
|
from common import (
|
|
add_common_args,
|
|
build_session,
|
|
resolve_common,
|
|
)
|
|
|
|
|
|
def list_stacks(session: requests.Session, base_url: str, board_id: int):
|
|
url = f"{base_url}/index.php/apps/deck/api/v1.0/boards/{board_id}/stacks"
|
|
headers = {"OCS-APIRequest": "true", "Accept": "application/json"}
|
|
resp = session.get(url, headers=headers)
|
|
if resp.status_code != 200:
|
|
raise RuntimeError(f"Deck API error: {resp.status_code} {resp.text}")
|
|
return resp.json()
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser(
|
|
description="List stacks (id + name) for a Nextcloud Deck board."
|
|
)
|
|
# Common flags (domain, board-id, username, password)
|
|
add_common_args(parser)
|
|
|
|
# Script-specific flags
|
|
parser.add_argument(
|
|
"--json",
|
|
action="store_true",
|
|
help="Output raw JSON instead of a table",
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
# Resolve common inputs (ENV -> CLI -> prompt)
|
|
try:
|
|
base_url, board_id, username, password = resolve_common(
|
|
cli_domain=args.domain,
|
|
cli_board_id=args.board_id,
|
|
cli_username=args.username,
|
|
cli_password=args.password,
|
|
)
|
|
except Exception as e:
|
|
print(f"❌ {e}", file=sys.stderr)
|
|
sys.exit(2)
|
|
|
|
session = build_session(username, password)
|
|
|
|
try:
|
|
stacks = list_stacks(session, base_url, int(board_id))
|
|
except Exception as e:
|
|
print(f"❌ Failed to fetch stacks: {e}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
if args.json:
|
|
print(json.dumps(stacks, ensure_ascii=False, indent=2))
|
|
return
|
|
|
|
if not stacks:
|
|
print("No stacks found.")
|
|
return
|
|
|
|
print(f"Stacks for board {board_id} at {base_url}:")
|
|
print("-" * 60)
|
|
print(f"{'ID':<8} {'NAME'}")
|
|
print("-" * 60)
|
|
for s in stacks:
|
|
sid = s.get("id")
|
|
title = s.get("title", "")
|
|
print(f"{str(sid):<8} {title}")
|
|
print("-" * 60)
|
|
print("Tip: use the ID in your importer script's --stack-id.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|