Clockify API,返回意外数据?

2024-09-28 17:24:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为使用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():

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

^{pr2}$

我只希望时间条目完成。有什么建议吗?在


Tags: 用户inapiurlfortime时间条目
1条回答
网友
1楼 · 发布于 2024-09-28 17:24:04

更新(10/16/19):

Another follow-up. They just send me an e-mail saying they fixed the problem. Putting the parameter "in-progress" to false will return only completed time entries. @matthew-e-miller it would be nice to add this to the answer. – Lukas Belck 5 hours ago


好吧,所以我终于有机会重现这个问题,看起来。。。时间没有尽头。它们误导性地提供了一个start和end参数,,但这两个参数都是在start time上过滤的。在

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

Clockify Start and End Overview

进行中的工作方式如doc中所述,但它不适用于您的应用程序。在

回答:

“最好用你的脚本把所有的元素都删除,然后用你的脚本把它们全部删除”。在

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)

输出:

仅包含没有时间间隔。结束=='无'。在

以下是编辑此答案所花的时间:

Clockify Time Spent On Question

相关问题 更多 >