当前位置: 首页>>代码示例>>Python>>正文


Python TrelloClient.all_cards方法代码示例

本文整理汇总了Python中trello.TrelloClient.all_cards方法的典型用法代码示例。如果您正苦于以下问题:Python TrelloClient.all_cards方法的具体用法?Python TrelloClient.all_cards怎么用?Python TrelloClient.all_cards使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trello.TrelloClient的用法示例。


在下文中一共展示了TrelloClient.all_cards方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from trello import TrelloClient [as 别名]
# 或者: from trello.TrelloClient import all_cards [as 别名]
class Trello:
    COMMENT_PREFIX = "external_id="
    log = logging.getLogger(__name__)

    def __init__(self):
        self.config = load_config("config/trello-config.yaml")
        self.cards_with_external_ids = []
        self.labels = {}

        app_key = self.config['app_key']
        token = self.config['token']
        board_id = self.config['board_id']

        self.board = TrelloClient(api_key=app_key, token=token).get_board(board_id)
        self.classify_board()
        self.log.debug("Connecting to Trello board {0}".format(board_id))

    def classify_board(self):
        cards = self.board.all_cards()
        self.log.debug("Classifying Trello board, contains {0} cards".format(len(cards)))

        for label in self.board.get_labels():
            self.labels[label.name] = label

        for card in cards:
            if card.closed:
                self.log.info("Ignoring closed card {0} ({1})".format(card.name, card.id))
            else:
                self.log.debug("Looking for external id in {0}".format(card.name))
                self.cards_with_external_ids.append(Trello.get_external_id(card))

    @staticmethod
    def get_external_id(card):
        external_id = None
        card.fetch()
        comments = card.comments
        if comments:
            for comment in comments:
                text = comment['data']['text']
                if Trello.COMMENT_PREFIX in text:
                    external_id = re.sub(Trello.COMMENT_PREFIX, '', text)
        return external_id

    def clear_board(self):
        for card in self.board.all_cards():
            self.log.info("Deleting {0} {1}".format(card.name, card.id))
            card.delete()

    def card_exists(self, identifier):
        return identifier in self.cards_with_external_ids

    def add_cards(self, cards):
        default_list = self.board.get_list(self.config['default_list'])
        self.log.info("Adding {0} cards to lane {1} ({2})".format(len(cards), default_list.name,
                                                                  default_list.id))
        for card in cards:
            name = card['name']
            identifier = card['identifier']
            card_type = card['type']
            note = card['note']

            card = default_list.add_card(name)
            if note is not None:
                card.set_description(note)
            card.comment("{0}{1}".format(Trello.COMMENT_PREFIX, identifier))

            try:
                card.add_label(self.labels[card_type])
                self.log.info("Creating card with details: name={0} id={1} type={2}".
                              format(name, identifier, card_type))
            except KeyError:
                self.log.info("Can't find card type {0} configured in Trello".format(card_type))
                self.log.info("Creating card with details: name={0} id={1} type=default".
                              format(name, identifier))

    def find_completed_card_ids(self):
        completed_lists = self.config['completed_lists']
        self.log.info("Looking for cards in completed lanes: {0}".format(completed_lists))
        cards = []

        for list_id in completed_lists:
            completed_list = self.board.get_list(list_id)
            cards.extend([Trello.get_external_id(card) for card in completed_list.list_cards()])

        # [cards.extend([card.external_card_id for card in self.trello.lane.get(lane).cards
        #                if len(card.external_card_id) > 1]) for lane in lanes]
        self.log.info("Found {0} completed cards on the board".format(len(cards)))
        self.log.debug("External ids: {0}".format(cards))
        return cards
开发者ID:rhydlewis,项目名称:omnifocus-to-kanban,代码行数:91,代码来源:kanban_board.py


注:本文中的trello.TrelloClient.all_cards方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。