def createClient(): token = getKey('token') if token != '' and token != 'your-oauth-token-key': return TrelloClient(api_key=getKey('api_key'), api_secret=getKey('api_secret'), token=token, token_secret=getKey('token_secret')) return TrelloClient(api_key=getKey('api_key'), api_secret=getKey('api_secret'))
def create_card(pedido): cliente = pedido.cliente placa_video = get_component(pedido, 'Placa de Vídeo') processador = get_component(pedido, 'Processadores') memoria = get_component(pedido, 'Memória RAM') disco = get_component(pedido, 'Disco Rígido/SSD') gabinete = get_component(pedido, 'Gabinete') placa_mae = get_component(pedido, 'Placa mãe') fonte = get_component(pedido, 'Fonte') data = { 'statu_pedido': str(pedido.statu_pedido), 'username': str(cliente.username), 'email': str(cliente.email), 'telefone': str(cliente.telefone), 'placa_video': str(placa_video), 'processador': str(processador), 'memoria': str(memoria), 'disco': str(disco), 'gabinete': str(gabinete), 'placa_mae': str(placa_mae), 'fonte': str(fonte), } client = TrelloClient(api_key=settings.API_KEY, token=settings.TRELLO_API_SECRET) if settings.BOARD_NAME: board = check_board(client.list_boards()) if client.list_hooks() == []: client.create_hook(settings.CALLBACK_DOMAIN, board.id) for lista in board.all_lists(): if lista.name == pedido.statu_pedido: lista.add_card(name=f'Pedido {pedido.id}', desc=loader.render_to_string( 'pedido_template.txt', data))
def __init__(self, token=None, **kwargs): super(ServiceTrello, self).__init__(token, **kwargs) # app name self.app_name = DjangoThConfig.verbose_name # expiration self.expiry = "30days" # scope define the rights access self.scope = 'read,write' self.oauth = 'oauth1' self.service = 'ServiceTrello' base = 'https://www.trello.com' self.AUTH_URL = '{}/1/OAuthAuthorizeToken'.format(base) self.REQ_TOKEN = '{}/1/OAuthGetRequestToken'.format(base) self.ACC_TOKEN = '{}/1/OAuthGetAccessToken'.format(base) self.consumer_key = settings.TH_TRELLO['consumer_key'] self.consumer_secret = settings.TH_TRELLO['consumer_secret'] if token: token_key, token_secret = token.split('#TH#') try: self.trello_instance = TrelloClient(self.consumer_key, self.consumer_secret, token_key, token_secret) except ResourceUnavailable as e: us = UserService.objects.get(token=token) logger.error(e.msg, e.error_code) update_result(us.trigger_id, msg=e.msg, status=False)
def update_trello(assignments): trello_api_key = os.environ['TRELLO_API_KEY'] trello_secret = os.environ['TRELLO_TOKEN'] logger.info('Connecting to Trello') client = TrelloClient(api_key=trello_api_key, api_secret=trello_secret) logger.info('Reading Trello boards') for board_obj in client.list_boards(): if board_obj.name == 'Work TODO': todo_board = board_obj logger.info('Reading Trello lists') for list_obj in todo_board.list_lists(): if list_obj.name == 'Teaching': teaching_list = list_obj for assignment in assignments: if not in_db(assignment): if not in_skipped_group(assignment): teaching_list.add_card('Grade ' + assignment.course_name + ': ' + assignment.name, 'Grade', due=str(datetime.datetime.now() + datetime.timedelta(days=7))) add_to_db(assignment) logger.info('Added Assignment {}:{}'.format( assignment.course_id, assignment.assignment_id)) else: logger.info('Skipped Assignment {}:{} (In Skip Group)'.format( assignment.course_id, assignment.assignment_id)) else: logger.info('Skipped Assignment {}:{} (In DB)'.format( assignment.course_id, assignment.assignment_id))
def get(self, request): try: token = request.GET.get('token') user = request.user if token is None: boards = None return super(BoardView, self).get(request) else: trello_client = TrelloClient(api_key=settings.TRELLO_APIKEY, token=token) boards = trello_client.list_boards() if boards: result = [h.delete() for h in trello_client.list_hooks()] print("delete trello hook :: result={}".format(result)) for board in boards: print("BOARD_ID:", board.id) slug_board = slugify(board.name, allow_unicode=False) b, created = Board.objects.get_or_create( name=slug_board, user=user, trello_board_id=board.id, trello_token=token) host = getenv("MATTERLLO_HOST") or request.get_host() url = "{}://{}/callback/{}/".format( request.scheme, host, b.id) result = trello_client.create_hook(url, board.id) print( "create trello hook :: callback={} :: board={} :: result={}" .format(url, slug_board, result)) return super(BoardView, self).get(request) except Exception as e: print("unable to display board :: {}".format(e)) return super(BoardView, self).get(request)
def __init__(self, credentials, boards=None): self.trello_client = TrelloClient( api_key=credentials['public_key'], token=credentials['member_token'], ) self.boards = boards
def __init__(self): trello_config = Config.open_api.trello self.client = TrelloClient(api_key=trello_config.API_KEY, api_secret=trello_config.API_SECRET, token=trello_config.TOKEN) self.board = self.client.get_board(trello_config.BOARD)
def get_trello_client(): '''Returns configured Trello client. Source .trello-creds if it exists. Otherwise prompt for required env vars. ''' if os.path.exists(CREDS_FILE): with open(CREDS_FILE) as stream: creds = json.loads(stream.read()) else: if not all([ os.environ.get('TRELLO_API_KEY'), os.environ.get('TRELLO_API_SECRET') ]): raise RuntimeError( 'Missing either TRELLO_API_KEY or TRELLO_API_SECRET for' ' initialization.\nThey can both be found at' ' https://trello.com/app-key') creds = { 'api_key': os.environ.get('TRELLO_API_KEY'), 'api_secret': os.environ.get('TRELLO_API_SECRET') } if not creds.get('token'): access_token = create_oauth_token(key=creds['api_key'], secret=creds['api_secret'], name='Trello Board Script') creds['token'] = access_token['oauth_token'] creds['token_secret'] = access_token['oauth_token_secret'] # Save credentials for next run with open(CREDS_FILE, 'w') as stream: stream.write(json.dumps(creds)) return TrelloClient(**creds)
def __init__(self, bot, slack, api_key=None, api_secret=None, oauth_token=None, oauth_secret=None): super().__init__(bot, slack) self.directed = True if not api_key: api_key = os.environ.get('TRELLO_API_KEY') if not api_secret: api_secret = os.environ.get('TRELLO_API_SECRET') if not oauth_token: oauth_token = os.environ.get('TRELLO_OAUTH_TOKEN') if not oauth_secret: oauth_secret = os.environ.get('TRELLO_OAUTH_SECRET') self.client = TrelloClient(api_key=api_key, api_secret=api_secret, token=oauth_token, token_secret=oauth_secret) self.org_name = os.environ.get('TRELLO_ORGANIZATION', 'pagarmeoficial') self.org_id = self.get_org_id(self.org_name) self.org = self.client.get_organization(self.org_id) self.set_job_status('Initialized')
def handle(self, *args, **options): trello = TrelloClient(settings.TRELLO_API_KEY, settings.TRELLO_TOKEN) master = Board.objects.get(name=settings.TRELLO_MASTER) self.compute_modifications(master) self.commit_updates_to_remote(trello, master) self.commit_newcards_to_remote(trello, master)
def post(self, request, *args, **kwargs): form = TodoItemImportTrelloForm(request.POST, ) if form.is_valid(): data = form.cleaned_data board_id = data['trello_id_board'] try: client = TrelloClient( api_key=request.user.profile.trello_api_key, api_secret=request.user.profile.trello_api_secret) desc = client.get_board(board_id) except: return render( request, 'tasks/import_trello.html', { 'form': form, 'error': 'check your api key and api secret and id board' }) left_list = desc.list_lists()[0] cards = left_list.list_cards() for card in cards: t = TodoItem(description=card.name, trello_id_board=board_id, trello_id_card=card.id) t.owner = request.user t.save() return redirect(reverse('tasks:list'))
def get(self, request, *args, **kwargs): if 'task_id' in kwargs: task = get_task_by_id(kwargs['task_id']) else: return Http404('Wrong reqest') task = get_task_by_id(kwargs['task_id']) if not task: return Http404('Task not found') task.is_completed = True task.save() try: client = TrelloClient( api_key=request.user.profile.trello_api_key, api_secret=request.user.profile.trello_api_secret) desc = client.get_board(task.trello_id_board) except: return Http404('Wrong reqest') # или тут -2 будет right_list = desc.list_lists()[-2] card = client.get_card(task.trello_id_card) card.change_list(right_list.id) return HttpResponse('OK')
def __init__(self, **entries): """ [summary] """ self.__dict__.update(entries) self.Trello = TrelloClient(api_key=self.apiK, api_secret=self.apiS) self.Bot = discord.Client() self.countW_P = 0 self.countW_TODO = 0 self.countW_Done = 0 self.countA_P = 0 self.countA_TODO = 0 self.countA_Done = 0 self.countS_P = 0 self.countS_TODO = 0 self.countS_Done = 0 self.reportExecute = False self.executionTime = 80 self.lastAction = None self.targetTime = None self.initTargetTime()
def __init__(self, instance, data={}, parent=None, interactive=False): JSConfigClient.__init__(self, instance=instance, data=data, parent=parent, template=TEMPLATE, interactive=interactive) from trello import TrelloClient if not self.config.data["token_secret_"]: print("**WILL TRY TO DO OAUTH SESSION") from trello.util import create_oauth_token access_token = create_oauth_token( key=self.config.data["api_key_"], secret=self.config.data["secret_"]) self.config.data_set("token_", access_token["oauth_token"]) self.config.data_set("token_secret_", access_token["oauth_token_secret"]) self.client = TrelloClient( api_key=self.config.data["api_key_"], api_secret=self.config.data["secret_"], token=self.config.data["token_"], token_secret=self.config.data["token_secret_"])
def clean(self): cleaned_data = super(TrelloSignUpForm, self).clean() # Get Trello remote data trello_client = TrelloClient( api_key=self.cleaned_data["api_key"], api_secret="xxx", token=self.cleaned_data["token"], token_secret=self.cleaned_data["token_secret"]) trello_member = TrelloMember(client=trello_client, member_id="me") try: trello_member.fetch() except Exception: raise ValidationError( u"Exception when dealing with Trello connection. Are your credentials right?" ) self.cleaned_data["uuid"] = trello_member.id self.cleaned_data["trello_username"] = trello_member.username self.cleaned_data["initials"] = trello_member.initials # Check if the user is already registered in the system. # To do so, we have to check if this Trello Member Profile has already an associated user if TrelloMemberProfile.objects.filter( trello_id=self.cleaned_data["uuid"], member__user__isnull=False).exists(): raise ValidationError( u"This Trello username already has an user in this system") return self.cleaned_data
def _get_trello_client(self): client = TrelloClient( api_key=self.trello_member_profile.api_key, api_secret=self.trello_member_profile.api_secret, token=self.trello_member_profile.token, token_secret=self.trello_member_profile.token_secret) return client
def handle(self, *args, **options): trello = TrelloClient(settings.TRELLO_API_KEY, settings.TRELLO_TOKEN) boards = trello.list_boards() ####################################################################### # INSTALL THE MASTER BOARD ############################################ ####################################################################### # check if the board exists m = self.__search_board_by_name(settings.TRELLO_MASTER, boards) # if not create it if m is None: m = trello.add_board(settings.TRELLO_MASTER, default_lists=False) try: master = Board.objects.get(remoteid=m.id) except Board.DoesNotExist: master = Board(remoteid=m.id) master.name = m.name master.closed = m.closed master.last_activity = None master.save() self.__install_lists(m, master) self.__install_labels(m, master) self.__install_members(m) ####################################################################### self.__install_projects_boards(trello, master, boards) self.__install_members_boards(trello, master, boards)
def __init__(self, api_key, token): """Creates a TrelloBoard object :param api_key: (str) Your Trello api key https://trello.com/1/appKey/generate :param token: (str) Your Trello token """ self.tc = TrelloClient(api_key=api_key, token=token)
def create(subjCod, task_title): config = configuration.load_config_file('polical.yaml') client = TrelloClient( api_key=config['api_key'], api_secret=config['api_secret'], token=config['oauth_token'], token_secret=config['oauth_token_secret'], ) subjectsBoard = client.get_board(config['board_id']) if (connectSQLite.check_no_subjectID(subjCod) == 1): subject_name = connectSQLite.getSubjectName(subjCod) print(subject_name) id = "" Add_Subject_To_Trello_List(subjectsBoard, subject_name, subjCod) elif (connectSQLite.getSubjectName(subjCod) == ""): print("\n Nombre de materia no encontrado, titulo de la tarea:" + task_title) subject_name = input("Por favor agregue el nombre de la materia:") response = "N" while response == "N" or response == "n": print("¿El nombre de la materia " + subject_name + " es correcto?") response = input("¿Guardar? S/N:") subject = MateriaClass.Materia(subject_name, subjCod) sql = connectSQLite.saveSubjects(subject) Add_Subject_To_Trello_List(subjectsBoard, subject_name, subjCod)
def __init__(self, apiKey, TOKEN): self.apiKey = apiKey self.token = TOKEN self.client = TrelloClient(api_key=apiKey, api_secret='your-secret', token=TOKEN, token_secret='your-oauth-token-secret')
def create(subjCod): config = configuration.load_config_file('polical.yaml') client = TrelloClient( api_key=config['api_key'], api_secret=config['api_secret'], token=config['oauth_token'], token_secret=config['oauth_token_secret'], ) member_id = config['owner_id'] subjectsBoard = client.get_board(config['board_id']) if (connectSQLite.check_no_subjectID(subjCod) == 1): subject_name = connectSQLite.getSubjectName(subjCod) print(subject_name) id = "" for x in subjectsBoard.list_lists(): if x.name == subject_name: id = x.id if id == "": subjectsBoard.add_list(subject_name) for x in subjectsBoard.list_lists(): if x.name == subject_name: id = x.id subject = MateriaClass.Materia(subject_name, subjCod, id) print(subject.print()) sql = connectSQLite.saveSubjectID(subject) for row in sql.fetchall(): print(row) sql = connectSQLite.getdb().close()
def __init__(self): self.client = TrelloClient(api_key=os.getenv("TRELLO_API_KEY"), api_secret=os.getenv("TRELLO_SECRET_KEY"), token=os.getenv("TRELLO_TOKEN")) self.board = self.client.list_boards()[0] self.lists = self.board.open_lists()
def get_trello_boards(): """ Get all Trello boards """ trello_client = TrelloClient(api_key=trello_api_key, api_secret=trello_api_secret, token=trello_token, token_secret=trello_token_secret) return trello_client.list_boards(board_filter="open")
def __init__(self, board_id, list_id, api_key, token=None, **kwargs): """ Validate inputs and connect to Trello API. Exception is thrown if input details are not correct. :param board_id: Trello board ID where the List is located :type board_id: ``str`` :param list_id: Trello List ID itself :type list_id: ``str`` :param api_key: Trello API key :type api_key: ``str`` :param token: Trello API token :type token: ``str`` """ self.board_id = board_id self.list_id = list_id self.api_key = api_key # assume empty string '' as None self.token = token or None self.validate() self._client = TrelloClient(api_key=self.api_key, token=self.token) self._list = self._client.get_board(self.board_id).get_list( self.list_id)
def MakeTrelloCard(title='My card', description='My description', board_name='My board', list_name='My list', api_key='', api_secret='', token='', token_secret='any'): """ For this you need a Trello API key, secret and token. Token secret can be any string, but should be altered for security purposes. """ from trello import TrelloClient client = TrelloClient(api_key=api_key, api_secret=api_secret, token=token, token_secret=token_secret) trello_boards = client.list_boards() for trello_board in trello_boards: if trello_board.name == board_name: target_board = trello_board break trello_lists = target_board.all_lists() for trello_list in trello_lists: if trello_list.name == list_name: target_list = trello_list break target_list.add_card(title, desc=description)
def main(): # 設定ファイルの読込 conf_file = 'conf.txt' config = configparser.ConfigParser() # 気持ち程度のエラー処理 try: # configのファイルを開く config.readfp(codecs.open(conf_file, "r", "utf8")) # パラメータの読み込み API_Key = config.get('API', 'API_Key') API_SECRET = config.get('API', 'API_SECRET') OAUTH_TOKEN = config.get('API', 'OAUTH_TOKEN') OAUTH_TOKEN_SECRET = config.get('API', 'OAUTH_TOKEN_SECRET') BOARD_NAME = config.get('ENV', 'BOARD_NAME') TAG_NAME = config.get('ENV', 'TAG_NAME') # 失敗した時はエラーとだけ伝える except: print("Error occured") exit() # クライアントを作成 client = TrelloClient(API_Key, API_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) # 緑ラベルカードの配列を呼び出し green_cards = get_green_cards(client, BOARD_NAME, TAG_NAME) # クリップボードにコピー copy_clipboard(green_cards)
def __init__(self, boardUrl:str, listForNewCards:str): trelloApiKey = os.getenv('TRELLO_API_KEY') trelloApiSecret = os.getenv('TRELLO_API_SECRET') trelloTokenKey = os.getenv('TRELLO_TOKEN_KEY') trelloTokenSecret = os.getenv('TRELLO_TOKEN_SECRET') if trelloApiKey == None: raise RuntimeError('TRELLO_API_KEY not set') if trelloApiSecret == None: raise RuntimeError('TRELLO_API_SECRET not set') if trelloTokenKey == None: raise RuntimeError('TRELLO_TOKEN_KEY not set') if trelloTokenSecret == None: raise RuntimeError('TRELLO_TOKEN_SECRET not set') self.trelloClient = TrelloClient(trelloApiKey, trelloApiSecret, trelloTokenKey, trelloTokenSecret) print('Connected with Trello') for board in self.trelloClient.list_boards(): board.fetch() if boardUrl == board.url: self.trelloBoard = board break print('Using trello board named '+self.trelloBoard.name+' with url: '+self.trelloBoard.url) for boardList in self.trelloBoard.all_lists(): boardList.fetch() if listForNewCards == boardList.name: self.trelloNewCardList = boardList print('Using trello list named '+self.trelloNewCardList.name)
def main(): client = TrelloClient( api_key=os.environ.get('TRELLO_API_KEY'), api_secret=os.environ.get('TRELLO_API_SECRET'), ) trello_filter = 'open' open_boards = client.list_boards(board_filter=trello_filter) for board in open_boards: print board.name planner = [board for board in open_boards if board.name == 'Planner'] if planner: planner = planner[0] else: raise Exception("Planner board not found") lists = planner.list_lists(list_filter=trello_filter) for l in lists: # l.add_card("name of card", "Comment") print l.name # card_filter is 'open' by default, everything else is 'all' for c in l.list_cards(card_filter=trello_filter): print u'- {}'.format(c.name) movements = c.list_movements() print "Moved {} times".format(len(movements)) # print c.fetch_comments(force=True) print c.card_created_date print c.date_last_activity
def save_to_trello(self): # print clean_form_data api_key = settings.TRELLO_KEY secret = settings.TRELLO_SECRET token = settings.TRELLO_TOKEN board = settings.TRELLO_REQUEST_BOARD c = TrelloClient(api_key, secret, token) b = c.get_board(board) # Currently we default to adding card to first list l = b.all_lists()[0] label_list = b.get_labels() ds_name = "%s - %s" % (self.dataset_name, self.dataset_source) ds_description = "%s\n%s\nRequested by: %s %s, %s" % \ (self.dataset_name, self.dataset_description, self.user_first_name, self.user_last_name, self.user_email) try: label_to_add = next(x for x in label_list if x.name == 'Request') except StopIteration: label_to_add = b.add_label('Request', "lime") try: card = l.add_card(ds_name, ds_description, [label_to_add]) self.trello_id = card.id except Exception: pass
def main(): # Vars to reference api_key = "API_KEY" api_token = "API_Token" board_id = "BOARD ID" todo_list_id = "TODO LIST_ID" done_list_id = "DONE LIST ID" client = TrelloClient(api_key=api_key, token=api_token) # Get a list of boards all_boards = client.list_boards() # Print a list of boards for board in all_boards: print(board.id + ":" + board.name) # Get our board amp_board = client.get_board(board_id) print_lists(amp_board) # Get the todo list todo_list = get_todo_list(amp_board, todo_list_id) created_card = create_card(client, todo_list) done_list = get_done_list(amp_board, done_list_id) # Move the list from TODO to Done list move_card(api_key, api_token, created_card.id, done_list) exit(0)