如何使用 python 从 Trello 读取清单
How do I read the checklists from Trello using python
我正在使用 python 从 Trello 看板检索某些卡片。这是我的代码:
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']
在卡片信息之上,我想从清单中获取常设项目并获取文本。我尝试了清单方法,但我不知道如何从那里读取属性。
我试过:
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)
cl 看起来像这样:
<Checklist 5be2356788378207b77cf02a>
如何访问核对表的信息?
谢谢。
这是一个函数,它接受一个 Trello 看板对象,例如您的 minutes_board
,并输出一个类似于 JSON 的对象。 IE。 a dict
由您的板列表的名称键控,其值也是字典,代表各自列表下的一张卡片。每张卡片都由卡片 id
键控,其值有 2 个字段:1) 卡片的 title/subject,以及 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
然后您可以使用类似 Python 的 pprint
模块来显示 return 对象以便于查看。
注意:我没有对创建日期进行过滤,我相信你应该能够自己弄清楚。但是如果你需要帮助,请告诉我。
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']
添加的代码是
for cl in card.fetch_checklists():
for k in len(cl)
print(cl[k].items)
cl[k].items
是一个列表,其中包含'name'(检查项的内容)等数据。这就是我要找的。
我正在使用 python 从 Trello 看板检索某些卡片。这是我的代码:
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']
在卡片信息之上,我想从清单中获取常设项目并获取文本。我尝试了清单方法,但我不知道如何从那里读取属性。
我试过:
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)
cl 看起来像这样:
<Checklist 5be2356788378207b77cf02a>
如何访问核对表的信息?
谢谢。
这是一个函数,它接受一个 Trello 看板对象,例如您的 minutes_board
,并输出一个类似于 JSON 的对象。 IE。 a dict
由您的板列表的名称键控,其值也是字典,代表各自列表下的一张卡片。每张卡片都由卡片 id
键控,其值有 2 个字段:1) 卡片的 title/subject,以及 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
然后您可以使用类似 Python 的 pprint
模块来显示 return 对象以便于查看。
注意:我没有对创建日期进行过滤,我相信你应该能够自己弄清楚。但是如果你需要帮助,请告诉我。
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']
添加的代码是
for cl in card.fetch_checklists():
for k in len(cl)
print(cl[k].items)
cl[k].items
是一个列表,其中包含'name'(检查项的内容)等数据。这就是我要找的。