1
0
Fork 0

openproject_hours: new script

This commit is contained in:
Luca Bilke 2024-10-16 11:14:01 +02:00
parent d2d552ea19
commit 0171baf659

View file

@ -0,0 +1,49 @@
#!/bin/sh
# shellcheck disable=2089,2090
year=$1
month=$2
USER_ID=12
API_KEY=$(cat "${HOME}/.secrets/openproject_apikey")
API_URL=https://op.tralios.de
PAGE_SIZE=1000
filters='[
{
"spentOn": {
"operator": "<>d",
"values": ["'"${year}-${month}-01"'", "'"${year}-${month}-30"'"]
}
},
{
"user": {
"operator": "=",
"values": ["'"$USER_ID"'"]
}
}
]'
curl -s \
-u "apikey:${API_KEY}" \
-G "${API_URL}/api/v3/time_entries" \
--data-urlencode "filters=${filters}" \
--data-urlencode "pageSize=${PAGE_SIZE}" |
jq -r '._embedded.elements | map(.hours) | join(" ")' |
awk '{
gsub(/PT/, "");
gsub(/H/, "H ");
gsub(/M/, "M ");
for (i=1; i<=NF; i++) {
if ($i ~ /H/) {
split($i, a, "H");
hours += a[1];
} else if ($i ~ /M/) {
split($i, a, "M");
hours += a[1] / 60;
}
}
}
END {
printf "%.2f\n", hours;
}'