Adding nicer status

This commit is contained in:
Philippe Caseiro 2022-03-23 16:44:32 +01:00
parent b169d2c6c0
commit cd2532b4c9

64
badgy
View File

@ -4,28 +4,79 @@ CURLIE="curlie"
clockin() clockin()
{ {
${CURLIE} POST ${BADGEURL}/clockin key=${KEY} ${CURLIE} POST ${BADGEURL}/clockin key=${KEY} 2> /dev/null
} }
clockout() clockout()
{ {
${CURLIE} POST ${BADGEURL}/clockout key=${KEY} ${CURLIE} POST ${BADGEURL}/clockout key=${KEY} 2> /dev/null
} }
validate() validate()
{ {
${CURLIE} POST ${BADGEURL}/validate key=${KEY} dateof=$(date +'%Y-%m-%d') ${CURLIE} POST ${BADGEURL}/validate key=${KEY} dateof=$(date +'%Y-%m-%d') 2> /dev/null
} }
devalidate() devalidate()
{ {
${CURLIE} POST ${BADGEURL}/devalidate key=${KEY} dateof=$(date +'%Y-%m-%d') ${CURLIE} POST ${BADGEURL}/devalidate key=${KEY} dateof=$(date +'%Y-%m-%d') 2> /dev/null
} }
s2h()
{
local sc=${1}
local h=$(( sc / 3600))
local m=$(( (sc % 3600) / 60 ))
local s=$(( sc % 60))
echo "${h}h${m}m"
}
getNewBalance()
{
local wk=25200
local blh=$(echo ${1} | cut -d ':' -f 1)
local blm=$(echo ${1} | cut -d ':' -f 2)
local bls=""
local nbls=""
echo ${nbls}
}
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
echo "Timers:"
for cl in ${clocks}
do
starts=$(echo ${cl} | jq -rc ".start")
st=$(date --date="${starts}" +'%s')
ends=$(echo ${cl} | jq -rc ".end")
echo
echo " Start: $(date --date=${starts} +'%A %d %B %Y : %H:%M')"
if [ "${ends}" != "null" ];then
ed=$(date --date="${ends}" +'%s')
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
echo "Your time balance is : ${sl}"
echo "Today you worked $(s2h ${dr})"
#echo "If you validate now your balance will be : ${nbl}"
}
show() show()
{ {
${CURLIE} POST ${BADGEURL}/showtimers key=${KEY} dateof=$(date +'%Y-%m-%d') ${CURLIE} POST ${BADGEURL}/showtimers key=${KEY} dateof=$(date +'%Y-%m-%d') 2> /dev/null
} }
if [ -e "${HOME}/.badgyrc" ]; then if [ -e "${HOME}/.badgyrc" ]; then
@ -50,6 +101,9 @@ case ${1} in
dev|devalidate|d) dev|devalidate|d)
devalidate | jq devalidate | jq
;; ;;
solde|sld|captial|s)
getCapitalTime
;;
*) *)
echo `${1}` | jq echo `${1}` | jq
;; ;;