要获取半月的Clockify已保存报告,你可以使用Clockify API来获取报告数据并保存到本地文件中。以下是一个示例代码,使用Python来获取半月的报告并保存为CSV文件:
import requests
import csv
from datetime import datetime, timedelta
# 设置API密钥和工作区ID
api_key = 'Your_Clockify_API_Key'
workspace_id = 'Your_Workspace_ID'
# 设置报告的起始和结束日期
end_date = datetime.now().date()
start_date = end_date - timedelta(days=15)
# 构建API请求的URL
url = f'https://reports.api.clockify.me/v1/workspaces/{workspace_id}/reports/summary'
# 设置请求头信息
headers = {
'X-Api-Key': api_key,
'Content-Type': 'application/json'
}
# 设置请求体参数
data = {
'dateRangeStart': start_date.isoformat(),
'dateRangeEnd': end_date.isoformat()
}
# 发送API请求
response = requests.post(url, headers=headers, json=data)
# 解析API响应
report_data = response.json()
# 提取所需数据
report_entries = report_data['timeentries']
# 将数据保存为CSV文件
with open('report.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(['Date', 'Description', 'Duration'])
for entry in report_entries:
date = entry['timeInterval']['start'][:10]
description = entry['description']
duration = entry['timeInterval']['duration']
writer.writerow([date, description, duration])
请确保替换Your_Clockify_API_Key
和Your_Workspace_ID
为你自己的API密钥和工作区ID。运行代码后,将会在当前目录下生成一个名为report.csv
的文件,其中包含了半月的报告数据。