···
hackatime-summary = pkgs.writeShellScriptBin "hackatime-summary" ''
129
+
while [[ $# -gt 0 ]]; do
if [[ -z "$user_id" ]]; then
user_id=$(${pkgs.gum}/bin/gum input --placeholder "Enter user ID" --prompt "User ID: ")
···
135
-
${pkgs.gum}/bin/gum spin --spinner dot --title "Fetching Hackatime summary for $user_id..." -- \
150
+
if [[ "$use_waka" = true ]]; then
151
+
host="waka.hackclub.com"
153
+
host="hackatime.hackclub.com"
156
+
${pkgs.gum}/bin/gum spin --spinner dot --title "Fetching summary from $host for $user_id..." -- \
${pkgs.curl}/bin/curl -s -X 'GET' \
137
-
"https://waka.hackclub.com/api/summary?user=''${user_id}&interval=month" \
158
+
"https://$host/api/summary?user=''${user_id}&interval=month" \
-H 'accept: application/json' \
-H 'Authorization: Bearer 2ce9e698-8a16-46f0-b49a-ac121bcfd608' \
142
-
${pkgs.jq}/bin/jq '. + {
143
-
"total_categories_sum": (.categories | map(.total) | add),
144
-
"total_categories_human_readable": (
145
-
(.categories | map(.total) | add) as $total_seconds |
146
-
"\($total_seconds / 3600 | floor)h \(($total_seconds % 3600) / 60 | floor)m \($total_seconds % 60)s"
149
-
.projects | sort_by(-.total) | map(.key)
151
-
}' /tmp/hackatime-$$.json
163
+
${pkgs.gum}/bin/gum style --bold --foreground 212 "Summary for $user_id"
166
+
# Extract and display total time
167
+
total_seconds=$(${pkgs.jq}/bin/jq -r '
168
+
if (.categories | length) > 0 then
169
+
(.categories | map(.total) | add)
170
+
elif (.projects | length) > 0 then
171
+
(.projects | map(.total) | add)
175
+
' /tmp/hackatime-$$.json)
177
+
if [[ "$total_seconds" -gt 0 ]]; then
178
+
hours=$((total_seconds / 3600))
179
+
minutes=$(((total_seconds % 3600) / 60))
180
+
seconds=$((total_seconds % 60))
181
+
${pkgs.gum}/bin/gum style --foreground 35 "Total time: ''${hours}h ''${minutes}m ''${seconds}s"
183
+
${pkgs.gum}/bin/gum style --foreground 214 "No activity recorded"
189
+
${pkgs.gum}/bin/gum style --bold "Top Projects:"
190
+
${pkgs.jq}/bin/jq -r '
191
+
if (.projects | length) > 0 then
192
+
.projects | sort_by(-.total) | .[0:10] | .[] |
193
+
" \(.key): \((.total / 3600 | floor))h \(((.total % 3600) / 60) | floor)m"
197
+
' /tmp/hackatime-$$.json
202
+
${pkgs.gum}/bin/gum style --bold "Top Languages:"
203
+
${pkgs.jq}/bin/jq -r '
204
+
if (.languages | length) > 0 then
205
+
.languages | sort_by(-.total) | .[0:10] | .[] |
206
+
" \(.key): \((.total / 3600 | floor))h \(((.total % 3600) / 60) | floor)m"
210
+
' /tmp/hackatime-$$.json
rm -f /tmp/hackatime-$$.json