badgy/badgy

124 lines
2.4 KiB
Plaintext
Raw Normal View History

2022-03-22 13:57:47 +01:00
#!/bin/bash
2022-03-22 13:59:24 +01:00
CURLIE="curlie"
2022-03-22 13:57:47 +01:00
clockin()
{
2022-03-23 16:44:32 +01:00
${CURLIE} POST ${BADGEURL}/clockin key=${KEY} 2> /dev/null
2022-03-22 13:57:47 +01:00
}
clockout()
{
2022-03-23 16:44:32 +01:00
${CURLIE} POST ${BADGEURL}/clockout key=${KEY} 2> /dev/null
2022-03-22 13:57:47 +01:00
}
validate()
{
2022-03-23 16:44:32 +01:00
${CURLIE} POST ${BADGEURL}/validate key=${KEY} dateof=$(date +'%Y-%m-%d') 2> /dev/null
2022-03-22 13:57:47 +01:00
}
devalidate()
{
2022-03-23 16:44:32 +01:00
${CURLIE} POST ${BADGEURL}/devalidate key=${KEY} dateof=$(date +'%Y-%m-%d') 2> /dev/null
2022-03-22 13:57:47 +01:00
}
2022-03-23 16:44:32 +01:00
s2h()
{
2022-03-24 13:07:30 +01:00
local sc=0
local sign=""
if [ ${1} -lt 0 ]; then
sign="-"
sc=$(echo ${1} | cut -c2-)
else
sc=${1}
fi
2022-03-23 16:44:32 +01:00
local h=$(( sc / 3600))
local m=$(( (sc % 3600) / 60 ))
local s=$(( sc % 60))
2022-03-24 13:07:30 +01:00
printf "%s%dh%02dm" "${sign}" "${h}" "${m}"
2022-03-23 16:44:32 +01:00
}
getNewBalance()
{
2022-03-24 13:07:30 +01:00
local workDay=25200
local blh=$(echo ${1} | cut -d ':' -f 1 | cut -c2-)
2022-03-23 16:44:32 +01:00
local blm=$(echo ${1} | cut -d ':' -f 2)
2022-03-24 13:07:30 +01:00
local bls=$((blh*3600 + blm*60))
local nbls=0
if [ "${bls}" -le "${workDay}" ]; then
nbls=$((${2}-(workDay - bls)))
else
nbls=$((bls+${2}))
fi
echo $nbls
2022-03-23 16:44:32 +01:00
}
getCapitalTime()
{
data=$(${CURLIE} POST ${BADGEURL}/showtimers key=${KEY} dateof=$(date +'%Y-%m-%d') 2> /dev/null)
clocks=$(echo ${data} | jq -rc ".timers[]")
sl=$(echo ${data} | jq -rc ".capitaltime")
dr=0
2022-03-24 13:07:30 +01:00
2022-03-23 16:44:32 +01:00
echo "Timers:"
for cl in ${clocks}
do
starts=$(echo ${cl} | jq -rc ".start")
2022-03-24 13:07:30 +01:00
st=$(date --date="${starts}" +'%s')
2022-03-23 16:44:32 +01:00
ends=$(echo ${cl} | jq -rc ".end")
2022-03-24 13:07:30 +01:00
echo
2022-03-23 16:44:32 +01:00
echo " Start: $(date --date=${starts} +'%A %d %B %Y : %H:%M')"
if [ "${ends}" != "null" ];then
2022-03-24 13:07:30 +01:00
ed=$(date --date="${ends}" +'%s')
2022-03-23 16:44:32 +01:00
echo " End: $(date --date=${ends} +'%A %d %B %Y : %H:%M')"
else
ed=$(date +'%s')
echo " End: running"
fi
dr=$(( dr + (ed - st)))
done
nbl=$(getNewBalance "${sl}" "${dr}")
echo
2022-03-24 13:07:30 +01:00
echo "Your time balance is: ${sl}"
2022-03-23 16:44:32 +01:00
echo "Today you worked $(s2h ${dr})"
2022-03-24 13:07:30 +01:00
echo "Balance if you validate now: $(s2h ${nbl})"
2022-03-23 16:44:32 +01:00
}
2022-03-22 13:57:47 +01:00
show()
{
2022-03-23 16:44:32 +01:00
${CURLIE} POST ${BADGEURL}/showtimers key=${KEY} dateof=$(date +'%Y-%m-%d') 2> /dev/null
2022-03-22 13:57:47 +01:00
}
if [ -e "${HOME}/.badgyrc" ]; then
. ${HOME}/.badgyrc
else
echo "${HOME}/.badgyrc file is missing, I need it"
echo "Create it with this command:"
echo " echo 'BADGEURL="https://myninebage" KEY="XXXX-XX-XXX-XXX"' > ${HOME}/.badyrc"
exit 2
fi
2022-03-24 13:07:30 +01:00
case ${1} in
2022-03-23 13:24:35 +01:00
in|clockin|c)
clockin | jq
;;
out|clockout|o)
clockout | jq
;;
val|validate|v)
validate | jq
;;
dev|devalidate|d)
devalidate | jq
;;
2022-03-23 16:44:32 +01:00
solde|sld|captial|s)
getCapitalTime
;;
2022-03-23 13:24:35 +01:00
*)
echo `${1}` | jq
;;
esac