Python 通过PyPi的Asana API模块将Asana任务导出到CSV
我需要将工作区特定项目中的所有Asana任务导出为csv文件。我一直通过Asana的高级搜索手动执行此操作,但Asana生成的csv文件仅支持<2000个条目,不再适合我的需要。下面的代码是我在网上找到的,稍作修改后的代码,除了我需要一个额外的“标记”列外,几乎满足了我的要求,就像Asana生成的csv文件显示了每个任务标记的逗号分隔列表一样。我需要标签的名称,而不是标签ID。我有Python的基本知识,但我没有API的经验,所以这真的超出了我的能力范围。如果有人能帮忙,我将不胜感激。以下是代码的相关位:Python 通过PyPi的Asana API模块将Asana任务导出到CSV,python,python-3.x,pypi,asana,asana-api,Python,Python 3.x,Pypi,Asana,Asana Api,我需要将工作区特定项目中的所有Asana任务导出为csv文件。我一直通过Asana的高级搜索手动执行此操作,但Asana生成的csv文件仅支持
import sys
import csv
import asana
def process_project_tasks(client, project, ws_dict):
"""Add each task for the current project to the records list."""
task_list = []
while True:
tasks = client.tasks.find_by_project(project['id']
{"opt_fields":"name, projects, workspace, id, due_on, created_at,
modified_at, completed, completed_at, assignee, assignee_status, parent,
notes"})
for task in tasks:
ws_name = ws_dict[task['workspace']['id']]
assignee = task['assignee']['id'] if task['assignee'] is not
None else ''
created_at = task['created_at'][0:10] + ' ' +
task['created_at'][11:16] if \
task['created_at'] is not None else None
modified_at = task['modified_at'][0:10] + ' ' +
task['modified_at'][11:16] if \
task['modified_at'] is not None else None
completed_at = task['completed_at'][0:10] + ' ' +
task['completed_at'][11:16] if \
task['completed_at'] is not None else None
rec = [task['name'], project['name'], ws_name,task['due_on'],
created_at, \
modified_at, task['completed'], completed_at, assignee, \
task['assignee_status'], task['parent'], task['notes'],
task['id']]
rec = ['' if s is None else s for s in rec]
task_list.append(rec)
if 'next_page' not in tasks:
break
return task_list
我研究了如何添加标签。您只需将“标签”添加为“opt_字段”之一。如果只是这样做,则无法获取标记的名称,因此需要将“opt_fields”更改为“opt_expand”,然后创建每个任务标记名称的逗号分隔列表
def process_project_tasks(client, project, ws_dict):
"""Add each task for the current project to the records list."""
while True:
tasks = client.tasks.find_by_project(project['gid'], {"opt_expand":"name, \
projects, workspace, gid, due_on, created_at, modified_at, completed, \
completed_at, assignee, assignee_status, parent, notes, tags"})
for task in tasks:
ws_name = ws_dict[task['workspace']['gid']]
#get a comma-separated list of the names of each tag
tags = task['tags']
if tags is not None:
tagname=''
i=0
for tag in tags:
if i==0:
tagname = tag['name']
else:
tagname = tagname + ', ' + tag['name']
i=i+1
assignee = task['assignee']['gid'] if task['assignee'] is not None else
''
created_at = task['created_at'][0:10] + ' ' + task['created_at'][11:16]
if \
task['created_at'] is not None else None
modified_at = task['modified_at'][0:10] + ' ' + task['modified_at']
[11:16] if \
task['modified_at'] is not None else None
completed_at = task['completed_at'][0:10] + ' ' + task['completed_at']
[11:16] if \
task['completed_at'] is not None else None
rec = [task['name'], project['name'], ws_name, task['due_on'],
created_at, \
modified_at, task['completed'], completed_at, assignee, \
task['assignee_status'], task['parent'], task['notes'], task['gid'],
tags]
rec = ['' if s is None else s for s in rec]
task_list.append(rec)
if 'next_page' not in tasks:
break
return task_list