diff options
-rwxr-xr-x | deckctl.py | 51 | ||||
-rwxr-xr-x | pending_chess.py | 28 |
2 files changed, 79 insertions, 0 deletions
diff --git a/deckctl.py b/deckctl.py new file mode 100755 index 0000000..cce2768 --- /dev/null +++ b/deckctl.py @@ -0,0 +1,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)) diff --git a/pending_chess.py b/pending_chess.py new file mode 100755 index 0000000..0cb1c24 --- /dev/null +++ b/pending_chess.py @@ -0,0 +1,28 @@ +#!/usr/bin/python3 +import chessdotcom +import chess +import datetime + +player = "steveclarney" + +lst = [] +data = chessdotcom.get_player_current_games(player) +for game in data.json["games"]: + white_player = game["white"][33:] + black_player = game["black"][33:] + player_side = "white" if player == white_player else "black" + other_player= white_player if player_side == "black" else black_player + game_type = game["rules"] + due = datetime.datetime.fromtimestamp(game["move_by"]) + if game["turn"] == player_side: + status = "Move by "+str(due) + else: + status = "Waiting..." + board = chess.Board(game["fen"]) + if player_side == "black": + board = board.transform(chess.flip_vertical) + board = board.transform(chess.flip_horizontal) + board_str = str(board.unicode(invert_color=True, empty_square=".")) + lst.append("vs. " + other_player + "\n" + status + "\n" + board_str) + +print(*[''.join(x) for x in zip(*[[x.ljust(29) for x in s.split('\n')] for s in lst])], sep='\n') |