iT邦幫忙

2023 iThome 鐵人賽

DAY 9
0

摘要

  • 今天是順藤摸瓜的系列,一層一層地開發函式,並且拿到卡片的細節系列的尾聲
  • 以下是最後兩個 function

get_tasks_in_project 函式

  • 在這個函式,單純給 project gid 或是運作者放在 config.ini 裡面的預設 project gid,就可以拿回所有 project 內的 tasks gid
def get_tasks_in_project(self, project_gid=None):
    try:
        # create an instance of the API class
        api_instance = asana.TasksApi(self.client)
        if project_gid is None:
            project_gid = self.default['my_project_gid']
        # Get multiple tasks
        api_response = api_instance.get_tasks_for_project(project_gid)
        data = api_response.to_dict()['data']
        # self.tasks = [ d['gid'] for d in data ]
        self.tasks = {}
        for d in data:
            self.tasks[d['gid']] = d['name']
    except ApiException as e:
        print("Exception when calling TasksApi->get_tasks_in_project: %s\n" % e)

get_tasks_in_project_details 函式

  • 看起來很類似上述函式,但不一樣
    • 這次透過 opt_fields 這個功能,給定我希望得到的內容,如此獲得較上次呼叫更詳細的回覆,卻又不全部都拿
    • (全部的細節都拿,會花的時間和傳輸的成本較高)
def get_tasks_in_project_details(self, project_gid=None, assignee_gid=None):
    try:
        # create an instance of the API class
        api_instance = asana.TasksApi(self.client)
        if project_gid is None:
            project_gid = self.default['my_project_gid']
        if assignee_gid is None:
            assignee_gid = self.default['my_user_gid']
        # Get multiple tasks
        opt_fields = ["approval_status","assignee","assignee.name","start_at","start_on","name"]
        api_response = api_instance.get_tasks_for_project(project_gid, opt_fields=opt_fields)
        data = api_response.to_dict()['data']
        # self.tasks = [ d['gid'] for d in data ]
        self.my_tasks = {}
        for d in data:
            if d['assignee'] is None:
                continue
            elif d['assignee']['gid'] == assignee_gid:
                self.my_tasks[d['gid']] = d
    except ApiException as e:
        print("Exception when calling TasksApi->get_tasks_in_project: %s\n" % e)

結論

  • 下一篇會有較詳細的說明

上一篇
Day 8 - 實作 Kanban 類別、取得 Asaba 工作區、團隊、專案的方法
下一篇
Day 10 - 根據 Asana 工作卡片產出投影片的流程設計
系列文
挽救肝指數 x 職場生存術 x 老闆愛看的投影片製造機30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言