Search code examples
pythontrello

How do I read the checklists from Trello using python


I am using python to retrieve certain cards from a Trello board. This is my code:

import trello
from trello import TrelloClient
import datetime
from dateutil.parser import parse
import re
import pandas as pd

client = TrelloClient(
api_key=mykey,
api_secret=myapisecret,
token=mytoken)

start_date = '2019-10-23 09:00:00'
end_date = '2019-10-25 14:00:00'

date = []
description = []
tag = []
comment = []
card_name = []
username = []

all_boards = client.list_boards()
minutes_board = all_boards[1]

for lists in minutes_board.list_lists():
    my_list = minutes_board.get_list(lists.id)   
    for card in my_list.list_cards():
        for j in range(len(card.comments)):
            comment_date = parse(card.comments[j]['date']).strftime("%Y-%m-%d %H:%M:%S")
            if comment_date >= start_date and comment_date <= end_date:
                text = card.comments[j]['data']['text']

On top of the card information, I want to get the standing items from a checklist and get the text. I tried the checklists method but I don't know how to read the properties from there.

I have tried:

for lists in minutes_board.list_lists():
    my_list = minutes_board.get_list(lists.id)   
    for card in my_list.list_cards():
        for cl in card.fetch_checklists():
            print(cl)

and cl looks like this:

<Checklist 5be2356788378207b77cf02a>

How can I access the info of the Checklist?

Thanks.


Solution

  • import trello
    from trello import TrelloClient
    import datetime
    from dateutil.parser import parse
    import re
    import pandas as pd
    
    client = TrelloClient(
    api_key=mykey,
    api_secret=myapisecret,
    token=mytoken)
    
    start_date = '2019-10-23 09:00:00'
    end_date = '2019-10-25 14:00:00'
    
    date = []
    description = []
    tag = []
    comment = []
    card_name = []
    username = []
    
    all_boards = client.list_boards()
    minutes_board = all_boards[1]
    
    for lists in minutes_board.list_lists():
        my_list = minutes_board.get_list(lists.id)   
        for card in my_list.list_cards():
            for cl in card.fetch_checklists():
                for k in len(cl)
                    print(cl[k].items)
            for j in range(len(card.comments)):
                comment_date = parse(card.comments[j]['date']).strftime("%Y-%m-%d %H:%M:%S")
                if comment_date >= start_date and comment_date <= end_date:
                    text = card.comments[j]['data']['text']
    

    The code added is

    for cl in card.fetch_checklists():
         for k in len(cl)
             print(cl[k].items)
    

    cl[k].items is a list with the data such as 'name' (content of the check item). That's what I was looking for.