From: Jakub Czajka Date: Sun, 17 Dec 2023 21:07:14 +0000 (+0100) Subject: Add a script for recording a new workout. X-Git-Url: https://git.ekhem.eu.org/?a=commitdiff_plain;h=3d5d5f52c94048e32ec52d523d4bbfe6aef4f1dc;p=gym.git Add a script for recording a new workout. --- diff --git a/record.sh b/record.sh new file mode 100755 index 0000000..8e575b7 --- /dev/null +++ b/record.sh @@ -0,0 +1,131 @@ +#!/bin/sh +# Copyright (c) 2023 Jakub Czajka +# License: GPL-3.0 or later. + +. /etc/environment + +exercises=$(/usr/bin/psql --user=gym_tracker --dbname="${GYM_DB}" \ + --tuples-only --no-align --command="\ +WITH per_gym_records AS ( + SELECT exercise_id, value + FROM gyms_records INNER JOIN gyms + ON gyms_records.gym_id = gyms.id + WHERE name = '${GYM}' +), records_all_exercises AS ( + SELECT * + FROM per_gym_records + UNION + SELECT * + FROM records + WHERE NOT EXISTS ( + SELECT * FROM + per_gym_records + WHERE per_gym_records.exercise_id = records.exercise_id + ) +) +SELECT exercises.id, name, value +FROM exercises LEFT OUTER JOIN records_all_exercises + ON exercises.id = records_all_exercises.exercise_id +ORDER BY exercises.id") + +format_for_html_input() { + /usr/bin/awk -F "|" '{printf "\ +
\ +\ +\ +\ +\ +\ +
",\ + $1, $2, $1, $3, $1, $1, $1, $1, $1, $1, $1, $1}' +} + +PAGE=" + + + + + + + +
+ + + + $(echo "${exercises}" | format_for_html_input) + +
+ +" + +echo "HTTP/1.1 200 OK" +echo "Content-Type: text/html" +echo "${PAGE}" | sed 's/^[ \t]*//g'