def __init__(self): """ init method """ super(TrelloExtension, self).__init__() LOGGER.info("Initializing Trello Extension") self.trello_client = TrelloClient(LOGGER) self.subscribe(KeywordQueryEvent, KeywordQueryEventListener()) self.subscribe(PreferencesEvent, PreferencesEventListener()) self.subscribe(PreferencesUpdateEvent, PreferencesUpdateEventListener())
import json import os import sys import re from datetime import datetime, timedelta from trello.client import TrelloClient TRELLO_CREDS = json.loads(os.getenv('TRELLO_CREDS')) TC = TrelloClient(**TRELLO_CREDS) ME = TC.get_member('me') NOW = datetime.now() TOMORROW = NOW + timedelta(days=1, minutes=-1) WEEKDAYS = ['Every day', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] YEAR, MONTH, DAY, WDAY, HOUR = NOW.year, NOW.month, NOW.day, NOW.isoweekday(), NOW.hour def parse_days(days): if days == '0': return set(range(1, 8)) days_split = days.split(';') days = set() for day in days_split: if '-' in day: start, end = day.split('-') days |= set(range(int(start), int(end) + 1)) else: days.add(int(day)) return days
def run(self): parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(help='commands') board_subparser = subparsers.add_parser('board', help='boards') \ .add_subparsers(help='board commands') board_list = board_subparser.add_parser('list', help='List boards') board_list.add_argument('-o', '--org', help='''List boards for specific organizations''') board_list.set_defaults(func=self.cmd_board_list) board_show = board_subparser.add_parser('show', help='Show board') board_show.add_argument('board_name', help='Name of board') board_show.set_defaults(func=self.cmd_board_show) org_parser = subparsers.add_parser('orgs', help='List organizations') org_parser.set_defaults(func=self.cmd_org_list) card_subparser = subparsers.add_parser('card', help='cards') \ .add_subparsers(help='card commands') card_list = card_subparser.add_parser('list', help='List cards') card_list.add_argument('-b', '--board', required=True, help='Limit to cards on board') card_list.set_defaults(func=self.cmd_card_list) card_show = card_subparser.add_parser('show', help='Show a card') card_show.add_argument('card', help='Name of card to show') card_show.set_defaults(func=self.cmd_card_show) card_copy = card_subparser.add_parser('copy', help='Copy card') card_copy.add_argument('--destlist', '-L', required=True, help='Destination list', dest='dest_listid', type=hex_string) card_copy.add_argument('source', help='Card ID to copy from', type=hex_string) card_copy.add_argument('dest_name', help='Name of copied card') card_copy.set_defaults(func=self.cmd_card_copy) list_subparser = subparsers.add_parser('list', help='board lists') \ .add_subparsers(help='list commands') list_list = list_subparser.add_parser('list', help='List lists') list_list.add_argument('boardid', help='ID of board', type=hex_string) list_list.set_defaults(func=self.cmd_list_list) list_show = list_subparser.add_parser('show', help='Show list') list_show.add_argument('listid', help='ID of list', type=hex_string) list_show.set_defaults(func=self.cmd_list_show) subparsers.add_parser('reconfig', help='Reconfigure the client') \ .set_defaults(func=self.cmd_setup) args = parser.parse_args() try: config = self.read_config() except NoConfigException: config = {} config['API_KEY'] = API_KEY config['API_URL'] = API_URL config['APP_NAME'] = APP_NAME client = TrelloClient(config) if not os.path.isfile(CONFIG): self.cmd_setup(client, args) else: args.func(client, args)
def get_burndown_totals(self): tc = TrelloClient(pin=self.pin) visitor = CardVisitor() tc.visit_cards(visitor, self.board_id) return visitor.get_totals()