def __init__(self, user_name, key, token): self.key = key self.token = token self.user_name = user_name self.org_api = Organizations(key, token) self.board_api = Boards(key, token) self.list_api = Lists(key, token) self.card_api = Cards(key, token) self.member_api = Members(key, token)
def __init__( self, user_name, key, token ): self.key = key self.token = token self.user_name = user_name self.org_api = Organizations(key, token ) self.board_api = Boards( key, token ) self.list_api = Lists( key, token ) self.card_api = Cards( key, token ) self.member_api = Members( key, token )
class Trello_Api: def __init__(self, user_name, key, token): self.key = key self.token = token self.user_name = user_name self.org_api = Organizations(key, token) self.board_api = Boards(key, token) self.list_api = Lists(key, token) self.card_api = Cards(key, token) self.member_api = Members(key, token) def organization_list_to_dictionary(self, key, convert_list, delete_function): return_value = {} for i in convert_list: if return_value.has_key(i[key]): if delete_function != None: delete_function(i["id"]) else: return_value[i[key]] = i return return_value def organization_creation_helper_organization(self, name, description, existing_list, create_function): if existing_list.has_key(name): return existing_list[name] else: return create_function(name, name, description) def organization_delete_helper(self, key, enity_dict, delete_function): if enity_dict.has_key(key): delete_function(enity_dict[key]["id"]) def list_to_dictionary(self, key, convert_list, delete_function, delete_flag=True): return_value = {} for i in convert_list: if i["closed"] == False: if return_value.has_key(i[key]): if delete_flag == True: delete_function(i["id"], "true") else: delete_function(i["id"]) else: return_value[i[key]] = i return return_value def creation_helper_parameter(self, name, description, parameter, existing_list, create_function): if existing_list.has_key(name): return existing_list[name] else: #print "creating ---------------------->",name if description != None: return create_function(name, description, parameter["id"]) else: return create_function(name, parameter["id"]) def delete_helper(self, name, enity_dict, delete_function, delete_flag=True): #print enity_dict.keys() if enity_dict.has_key(name): element_id = enity_dict[name]["id"] if delete_flag == True: delete_function(element_id, "true") else: delete_function(element_id) # # Organization # # def find_organizations(self): return self.organization_list_to_dictionary( "displayName", self.member_api.get_organization(self.user_name), self.org_api.delete) def create_organization(self, name, description): return self.organization_creation_helper_organization( name, description, self.find_organizations(), self.org_api.new) def delete_organization(self, name): self.organization_delete_helper(name, self.find_organizations(), self.org_api.delete) def update_org_description(self, org_element, description): self.org_api.update_desc(org_element["id"], description) # # # Boards # # def find_boards(self, organization): return self.list_to_dictionary( "name", self.org_api.get_board(organization["id"]), self.board_api.update_closed) def create_board(self, organization, name, description): temp = self.find_boards(organization) if temp.has_key(name) == False: board = self.creation_helper_parameter( name, description, organization, self.find_boards(organization), self.board_api.new) lists = self.board_api.get_list(board["id"]) for i in lists: self.list_api.update_closed(i["id"], "true") else: board = temp[name] return board def delete_board(self, organization, name): self.delete_helper(name, self.find_boards(organization), self.board_api.update_closed) def update_board_description(self, board_element, description): self.board_api.update_desc(board_element["id"], description) def find_lists(self, board): return self.list_to_dictionary("name", self.board_api.get_list(board["id"]), self.list_api.update_closed) def create_list(self, board, name, description): list_element = self.creation_helper_parameter(name, None, board, self.find_lists(board), self.list_api.new) return list_element def delete_list(self, board, name): self.delete_helper(name, self.find_lists(board), self.list_api.update_closed) def update_board_background_color(self, board, value): #color value resp = requests.put("https://trello.com/1/boards/%s/prefs/background" % (board["id"]), params=dict(key=self.key, token=self.token), data=dict(value=value)) resp.raise_for_status() return json.loads(resp.content) # # # Cards # # def find_cards(self, list_element): return self.list_to_dictionary( "name", self.list_api.get_card(list_element["id"]), self.card_api.delete, False) def create_card(self, list_element, name, description): card_element = self.creation_helper_parameter( name, None, list_element, self.find_cards(list_element), self.card_api.new) return card_element def delete_card(self, list_element, name): self.delete_helper(name, self.find_cards(list_element), self.card_api.delete, False) def update_card_description(self, card_element, text): self.card_api.update_desc(card_element["id"], text) def remove_card_label(card_element, value): try: self.card_api.delete_label_color(value, card_element["id"]) except: pass def add_card_label(self, card_element, color): try: self.card_api.new_label(card_element["id"], color) except: pass def delete_card_label(self, card_element, color): try: self.card_api.delete_label_color(color, card_element["id"]) except: pass def add_card_comment(self, card_element, text): self.card_api.new_action_comment(card_element["id"], text)
from trello import Boards from trello import Members import unicodedata def norm(dataunicode): return unicodedata.normalize('NFKD', dataunicode).encode('ascii', 'ignore') KEY = '5869b53180c8e5a19ae1e9a9d2d94916' TOKEN = 'a6c38225f99c5e4cf6ad8c4fc8149a1af77552c0d3f54cf367089f2255d451b3' BOARD_ID = '5af5977d264baece554c3fec' # DESENV membros = Members(KEY, TOKEN) boards = Boards(KEY, TOKEN) cards = boards.get_card(BOARD_ID) cabecalho = 'nome_tarefa' + ';' + 'responsavel' + ';' + 'labels' + ';' + 'data' + ';' + 'feito' print(cabecalho) for i in cards: if len(i[u'idMembers']) > 0: dono = membros.get(i[u'idMembers'][0]) nome_dono = dono[u'username'] else: nome_dono = 'Sem dono' lista_labels = '' if len(i[u'labels']) > 0: for j in i[u'labels']: lista_labels = lista_labels + '|' + j[u'name'] if i[u'due']: data = '' + i[u'due']
class Trello_Api: def __init__( self, user_name, key, token ): self.key = key self.token = token self.user_name = user_name self.org_api = Organizations(key, token ) self.board_api = Boards( key, token ) self.list_api = Lists( key, token ) self.card_api = Cards( key, token ) self.member_api = Members( key, token ) def organization_list_to_dictionary( self,key, convert_list, delete_function ): return_value = {} for i in convert_list: if return_value.has_key(i[key]): if delete_function != None: delete_function( i["id"] ) else: return_value[i[key]] = i return return_value def organization_creation_helper_organization( self, name, description, existing_list, create_function ): if existing_list.has_key(name): return existing_list[name] else: return create_function( name,name, description ) def organization_delete_helper( self, key, enity_dict, delete_function ): if enity_dict.has_key(key) : delete_function( enity_dict[key]["id"] ) def list_to_dictionary( self, key, convert_list, delete_function,delete_flag = True ): return_value = {} for i in convert_list: if i["closed"] == False: if return_value.has_key(i[key]): if delete_flag == True: delete_function( i["id"], "true" ) else: delete_function( i["id"] ) else: return_value[i[key]] = i return return_value def creation_helper_parameter( self, name, description, parameter, existing_list, create_function ): if existing_list.has_key(name): return existing_list[name] else: #print "creating ---------------------->",name if description != None: return create_function( name, description, parameter["id"] ) else: return create_function( name, parameter["id"] ) def delete_helper( self, name, enity_dict, delete_function , delete_flag = True ): #print enity_dict.keys() if enity_dict.has_key(name) : element_id = enity_dict[name]["id"] if delete_flag == True: delete_function( element_id,"true") else: delete_function( element_id ) # # Organization # # def find_organizations( self ): return self.organization_list_to_dictionary( "displayName", self.member_api.get_organization( self.user_name ), self.org_api.delete ) def create_organization( self, name, description ): return self.organization_creation_helper_organization( name, description, self.find_organizations(), self.org_api.new ) def delete_organization( self, name ): self.organization_delete_helper( name, self.find_organizations(), self.org_api.delete ) def update_org_description( self, org_element, description ): self.org_api.update_desc( org_element["id"],description) # # # Boards # # def find_boards( self, organization ): return self.list_to_dictionary( "name", self.org_api.get_board( organization["id"] ) , self.board_api.update_closed ) def create_board( self, organization, name, description ): temp = self.find_boards( organization ) if temp.has_key(name) == False: board = self.creation_helper_parameter( name, description, organization, self.find_boards( organization ), self.board_api.new ) lists = self.board_api.get_list(board["id"]) for i in lists: self.list_api.update_closed(i["id"],"true") else: board = temp[name] return board def delete_board( self, organization, name ): self.delete_helper( name, self.find_boards( organization ), self.board_api.update_closed ) def update_board_description( self, board_element, description ): self.board_api.update_desc( board_element["id"],description) def find_lists( self, board ): return self.list_to_dictionary("name", self.board_api.get_list(board["id"]), self.list_api.update_closed ) def create_list( self, board, name, description ): list_element = self.creation_helper_parameter( name, None, board, self.find_lists( board), self.list_api.new ) return list_element def delete_list( self, board, name ): self.delete_helper( name, self.find_lists( board ), self.list_api.update_closed ) def update_board_background_color(self, board, value): #color value resp = requests.put("https://trello.com/1/boards/%s/prefs/background" % (board["id"]), params=dict(key=self.key, token=self.token), data=dict(value=value)) resp.raise_for_status() return json.loads(resp.content) # # # Cards # # def find_cards( self, list_element ): return self.list_to_dictionary("name", self.list_api.get_card(list_element["id"]), self.card_api.delete , False) def create_card( self, list_element, name, description ): card_element = self.creation_helper_parameter( name, None , list_element, self.find_cards(list_element), self.card_api.new ) return card_element def delete_card( self, list_element, name ): self.delete_helper( name, self.find_cards( list_element ), self.card_api.delete,False ) def update_card_description( self, card_element,text): self.card_api.update_desc( card_element["id"], text ) def remove_card_label( card_element,value ): try: self.card_api.delete_label_color( value,card_element["id"] ) except: pass def add_card_label( self, card_element, color ): try: self.card_api.new_label( card_element["id"] , color ) except: pass def delete_card_label( self, card_element, color): try: self.card_api.delete_label_color( color, card_element["id"] ) except: pass def add_card_comment(self, card_element, text ): self.card_api.new_action_comment( card_element["id"], text)