[Tutorial][Trello] How to create cards.

My boss is really good at this. This paragraph is a result of his refactoring, my original version was like three times as long.

So you want to create some cards on some new lists.

def create_cards_on_new_lists(new_board_lists, master_lists, board_labels):
    new_cards = []
    for list_name, cards in new_board_lists.items():
        for card in cards:
            new_board_lists[list_name].add_card(card.name, desc=card.description, labels=board_labels[list_name])
    return new_cards

He also introduced me to this double element for loops with dictionaries.

for a, b in dict.items():

It gives you a tuple¬†with two elements (a, b), which correspond to key and element. It’s pretty handy when you’ve got a dictionary and a lot to sort through.

So for list_name, cards in new_board_lists.items() (the dict is keyed to list names so you’re looking at a (list_name, list_of_cards) kind of situation):

Go through all the cards:

On lists that match the list_name (that corresponds to the “cards”), add a card with the selected card’s name and description, and also add the board_labels[list_name] label.

board_labels is a dict also keyed to list_names that corresponds to the label I added to each board.

I’m not sure I follow all of it, but I wanted to write it down before I forgot too much of it. I hope I can get a lot better at using Python.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s