【问题标题】:Exporting Asana tasks to CSV via PyPi's Asana API module通过 PyPi 的 Asana API 模块将 Asana 任务导出到 CSV
【发布时间】:2019-06-01 11:12:09
【问题描述】:

我需要将我工作区的特定项目中的所有 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

【问题讨论】:

    标签: python python-3.x pypi asana asana-api


    【解决方案1】:

    我想出了如何添加标签。您只需添加“标签”作为“选择字段”之一。如果您只是这样做,则无法获取标签的名称,因此您需要将“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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-23
      相关资源
      最近更新 更多