简体   繁体   English

如何使用 python 从 Trello 读取清单

[英]How do I read the checklists from Trello using python

I am using python to retrieve certain cards from a Trello board.我正在使用 python 从 Trello 板上检索某些卡。 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:和 cl 看起来像这样:

<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.这是一个 function,它采用 Trello 板 object,例如您的minutes_board ,并输出类似 JSON 的 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.即由您的董事会列表名称键入的dict ,其值也是字典,代表各自列表下的一张卡片。 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.每张卡片都由它们的卡片id键入,其值有 2 个字段:1) 卡片的标题/主题,以及 2) 包含该卡片所有评论文本的 Python 列表。

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.然后,您可以使用类似 Python 的pprint模块来显示返回 object 以便于查看。

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). cl[k].items是一个包含“名称”(检查项目的内容)等数据的列表。 That's what I was looking for.这就是我一直在寻找的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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