1

我正在使用Clockify API () 为用户请求一些时间条目。出于某种原因,我收到了一些回复,其中包括没有结束时间的条目。我注意到,意外返回的条目属于当前运行时间的整体......但是,我没有指定/使用'in-progress'参数......这里发生了什么?

这是我的代码:

def fetch_users_time_entries(users):
    API_URL = "https://api.clockify.me/api/v1"
    for user in users:
        url = "{}/workspaces/{}/user/{}/time-entries?hydrated=true&page-size=1000&start=2019-08-05T00:00:01Z".format(API_URL, WORKSPACE_ID, user['clockify_id'])
        time_entries = requests.get(url, headers=HEADER)
        for time_entry in time_entries.json():

以下是意外“结束”值的示例:

{  
   'id':'SECRET',
   'description':'',
   'tags':[  
      {  
         'id':'SECRET',
         'name':'CERTI',
         'workspaceId':'SECRET'
      }
   ],
   'user':None,
   'billable':True,
   'task':{  
      'id':'SECRET',
      'name':'Etapa: Execução e Controle',
      'projectId':'SECRET',
      'assigneeId':'',
      'estimate':'PT0S',
      'status':'ACTIVE'
   },
   'project':{  
      'id':'SECRET',
      'name':'C105',
      'hourlyRate':{  
         'amount':0,
         'currency':'USD'
      },
      'clientId':'SECRET',
      'workspaceId':'SECRET',
      'billable':True,
      'memberships':[  
         {  
            'userId':'SECRET',
            'hourlyRate':None,
            'targetId':'SECRET',
            'membershipType':'PROJECT',
            'membershipStatus':'ACTIVE'
         }
      ],
      'color':'#8bc34a',
      'estimate':{  
         'estimate':'PT0S',
         'type':'AUTO'
      },
      'archived':False,
      'duration':'PT25H20M12S',
      'clientName':'NEO',
      'public':True
   },
   'timeInterval':{  
      'start':'2019-08-22T18:55:55Z',
      'end':None,
      'duration':None
   },
   'workspaceId':'SECRET',
   'totalBillable':None,
   'hourlyRate':None,
   'isLocked':False,
   'userId':'SECRET',
   'projectId':'SECRET'
}

我只期待完成的时间条目。有什么建议么?

4

1 回答 1

1

更新(19 年 10 月 16 日):

另一个跟进。他们只是给我发了一封电子邮件,说他们解决了这个问题。将参数“in-progress”设置为 false 将仅返回已完成的时间条目。@matthew-e-miller 很高兴将其添加到答案中。– 卢卡斯·贝尔克 5 小时前


好的,所以我终于有机会重现这个问题,而且似乎......没有结束时间过滤器。他们误导性地提供了 start 和 end 参数,但它们都在 start-time 上过滤

开始和结束参数的工作方式如下:

Clockify 开始和结束概述

进行中的工作如d​​oc中所述,但不适用于您的应用程序。

回答:

我认为您最好的选择是请求所有时间条目,将它们放入字典/列表中,然后使用您的 python 脚本删除带有“'end:'None'”的元素。

import requests
import json

headers = {"content-type": "application/json", "X-Api-Key": "your api key""}

workspaceId = "your workspace id"
userId = "your user id"
params = {'start': '2019-08-28T11:10:32.998Z', 'end': '2019-08-29T02:05:02Z', 'in-progress': 'true'}
API_URL = "https://api.clockify.me/api/v1/workspaces/{workspaceId}/user/{userId}/time-entries"

print(API_URL)
result_one = requests.get(API_URL, headers=headers, params=params)
print(result_one)
List = json.loads(result_one.text)
for entry in List:
    if entry.get("timeInterval")['end'] == None:
      List.remove(entry)
print(List)

输出:

仅包含没有 timeInterval.end == 'None' 的条目的列表。

这是花费在此答案编辑上的时间:

时钟花在问题上的时间

于 2019-08-23T02:27:36.783 回答