Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
def get_actions(card_id):
    card = Cards(TRELLO_APP_KEY, TRELLO_APP_TOKEN)
    actions = card.get_action(card_id)
    update_actions = []
    get_lead_time(actions)
    for action in actions:
        if action['type'] != 'commentCard':
            update_actions.append(action)
            list_before = action['data']['listBefore']['name']
            list_after = action['data']['listAfter']['name']
    return update_actions
Ejemplo n.º 3
0
 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 )
Ejemplo n.º 4
0
    async def on_ready(self):
        # Access API access information in Creds.ini
        config = configparser.ConfigParser()
        config.read("Creds.ini")

        # How to reference the Trello board
        global board
        global b_id
        # How to reference a list on the Trello board
        global c_list
        # How to reference a card on the Trello board
        global cards
        board = Boards(config.get('trello', 'api_key'),
                       config.get('trello', 'token'))
        b_id = config.get('trello', 'board_id')
        c_list = Lists(config.get('trello', 'api_key'),
                       config.get('trello', 'token'))
        cards = Cards(config.get('trello', 'api_key'),
                      config.get('trello', 'token'))
        print("Trello online.")
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
def get_members(card_id):
    card = Cards(TRELLO_APP_KEY, TRELLO_APP_TOKEN)
    members = card.get_member(card_id)
    return members
Ejemplo n.º 8
0
boardId = data["actions"][0]["data"]["board"][
    "id"]  # ID of the board we're working on

print(
    "Copy and paste the following link in your web browser to get a new token."
)
print(
    trello.get_token_url("Similar Label Detector",
                         expires="30days",
                         write_access=True))
# visit site to get 64-character token
# token given by website
auth_token = "744be46a0777522b10e26f42a819274dcbdc490bfc6d927960dc555d0fdb94b7"
trello.set_token(auth_token)

cards = Cards(app_key, auth_token)
boards = Boards(app_key, auth_token)

cardIds = []  # empty list where we will store card ID's
label_names = []  # empty list where we will store unmodified label names
label_names_lc = []  # empty list where we will store lowercase label names

print(
    "\nList of cards, their respective ID's, and their respective label names:"
)

for x in range(0, len(boards.get_card(boardId))):  # 0 to 9, because 10 cards
    y = boards.get_card(boardId)[x]  # get every individual card's info
    card = y["name"]  # get card's description
    card_id = y["shortLink"]  # get card's ID
    # exception handling: some cards have no label whatsoever, so the "name" key doesn't exist in the "label section"
TRELLO_CONFIG = {
    'api_key': 'TRELLO_API_KEY',
    'oauth_token': 'TRELLO_OAUTH_TOKEN_FOR_BOARD',
    'board_id': 'BOARD_ID',
    'list_id_in_progress': 'LIST_ID',
    'list_id_done': 'LIST_ID',
}

WEBHOOK_CONFIG = {
    'host': '0.0.0.0',
    'port': 7343
}

TRELLO_LIST = Lists(TRELLO_CONFIG['api_key'], TRELLO_CONFIG['oauth_token'])
TRELLO_CARDS = Cards(TRELLO_CONFIG['api_key'], TRELLO_CONFIG['oauth_token'])


@route("/")
def index():
    return 'git webhook for move trello cards'


@route("/webhook", method='POST')
def handle_payload():
    json_payload = None
    from_gitlab = False
    if request.get_header('Content-Type', None) == 'application/json':
        json_payload = request.json
        from_gitlab = True
    else: