diff --git a/common/.local/bin/openproject_hours b/common/.local/bin/openproject_hours new file mode 100755 index 00000000..53d8b694 --- /dev/null +++ b/common/.local/bin/openproject_hours @@ -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; + }'