summaryrefslogtreecommitdiff
path: root/deckctl.py
blob: cce2768290270980de6d6959a44a49ff56103542 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python3

import subprocess, re
def get_stacks(board):
    return subprocess.check_output(
        ['/home/mark/go/bin/deckctl', 'list', 'stacks', '--board', board], 
        encoding='UTF-8')
def get_cards(stack, board):
    return subprocess.check_output(
        ['/home/mark/go/bin/deckctl', 'list', 'cards', '--stack', stack, '--board', board],
        encoding='UTF-8')

def get_item_or_empty(lst, index):
    if index < len(lst):
        return lst[index]
    return ""

board = "School"
stack_output = get_stacks(board)
stacks = []
all_cards = []
for line in stack_output.splitlines():
    if re.search('^\s+.+', line):
        stack = line.strip()
        stacks.append(stack)
for stack in stacks:
    cards = []
    try:
        card_output = get_cards(stack, board)
        for card_line in card_output.splitlines():
            if re.search('^\s+.+', card_line):
                card = card_line.strip()
                cards.append(card)
    except subprocess.CalledProcessError as exc:
        continue
    finally:
        all_cards.append(cards)
max_cards=0
for cards in all_cards:
    if len(cards) > max_cards:
        max_cards = len(cards)
print("-"*(17 * len(stacks) + 1))
for stack in stacks:
    print(f"|{stack:16}", end ="")
print("|")
print("-"*(17 * len(stacks) + 1))
for i in range(max_cards):
    for cards in all_cards:
        print(f"|{get_item_or_empty(cards, i):16}", end ="")
    print("|")
print("-"*(17 * len(stacks) + 1))