简体   繁体   中英

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.

Here's a function that takes a Trello board object, like your minutes_board for example, and outputs a JSON-like object. Ie a dict keyed by the names of your board lists, whose values are also dictionaries, representing a single card under their respective list. Each card is keyed by their card id , with 2 fields for its value: 1) the card's title/subject, and 2) a Python list containing all comments texts for that card.

def get_comment_texts(tboard):
    board_content = {}
    for ls in tboard.list_lists():
        list_content = {}
        for card in ls.list_cards():
            card_info = {}
            cid = card.id
            card_info['title'] = card.name
            comments = card.fetch_comments()
            texts = []
            for c in comments:
                texts.append(c['data']['text'])
            card_info['comments'] = texts
            list_content[cid] = card_info
        board_content[ls.name] = list_content
    return board_content

You can then use something like Python's pprint module to display the return object for easier viewing.

Note: I didn't bother doing a filter on the creation date, which I believe you should be able to figure out on your own. But you if you need help with that, just let me know.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM