diff --git a/scripts/walletsBalance.sh b/scripts/walletsBalance.sh index 6040f55..21d5304 100755 --- a/scripts/walletsBalance.sh +++ b/scripts/walletsBalance.sh @@ -1,44 +1,51 @@ #!/bin/bash -# Récupération du chemin absolut du répertoir du script actuel +# Récupération du chemin absolu du répertoire du script actuel GPATH="$( cd "$(dirname "$0")" ; pwd -P )/.." [[ ! -f $GPATH/.env ]] && cp $GPATH/.env.example $GPATH/.env source $GPATH/.env node=$(cut -d '/' -f3 <<<"$DUNITER") -#Check if Jaklis is installed -[[ -z $JAKLIS ]] && JAKLIS=$(which silkaj) -[[ -z $JAKLIS ]] && echo "Erreur: Vous devez installer Jaklis." && exit 1 +#Check if ed is installed +which ed || { echo "$0: Error: please install ed" >&2 ; exit 1 ; } + +#Check if Jaklis or silkaj is installed +if [[ "$JAKLIS" ]] ; then + exec() { + jsonResult=$($JAKLIS idBalance -p $i) || return $? + balance=$(echo "$jsonResult" | jq -r '.balance') + username=$(echo "$jsonResult" | jq -r '.username') + } +elif which silkaj ; then + exec() { + balance=$(silkaj -p "$node" balance "$i") || return $? + balance=$(sed -n 's,.* \([\.0-9]\+\) Ğ1.*,\1,p' <<<$balance) + username=$(silkaj -p "$node" id "$i") || return $? + username=$(sed -n 's,.*: \(.*\)$,\1,p' <<<$username) + } +else + echo "$0: Error: you should use Jaklis or install silkaj." >&2 + exit 1 +fi work() { - for i in $wallets; do - exec() { - jsonResult=$($JAKLIS idBalance -p $i 2>/dev/null) - } - exec - while [[ $? == 1 ]]; do echo "Erreur $k: $i"; ((k++)); exec; done - unset k + for i in $wallets; do + ((j++)) + # For tests only + #(( j > 42 )) && break - balance=$(echo "$jsonResult" | jq -r '.balance') - username=$(echo "$jsonResult" | jq -r '.username') - formatedBalance=$(printf "%-10s | %-45s | %-1s" $balance $i $username) + unset k + while ! exec ; do echo "Erreur $?: retry=$((k)) wallet=$i"; ((k++ > 9999)) && break ; sleep $((RANDOM%8)) ; done - if [[ $1 == "members" ]]; then - htmlBloc="$htmlBloc"$'\n'"$balance$i$username" - unset username - else - htmlBloc="$htmlBloc"$'\n'"$balance$i$username" - fi - unset balance + formatedBalance=$(printf "%-10s | %-45s | %-1s" $balance $i $username) - echo "$formatedBalance" | tee -a /tmp/balance-g1.txt + [[ $1 == "members" ]] && username="$username" + htmlBloc="$htmlBloc$balance$i$username"$'\n' - totalBalance="$totalBalance"$'\n'"$formatedBalance" + echo "$formatedBalance" | tee -a /tmp/balance-g1.txt | sed "s,^,$j | ," - # For tests only -# [[ $i == "13fn6X3XWVgshHTgS8beZMo9XiyScx6MB6yPsBB5ZBia" ]] && break -# [[ $i == "12JDJibbgZPRfD6Hoecg8rQRvCR5VYrMnqzfhQYmAr3k" ]] && break - done + totalBalance="$totalBalance$formatedBalance"$'\n' + done } wallets=$(cat $WEBPATH/data/wallets-g1-membres.txt 2>/dev/null) @@ -57,7 +64,7 @@ cp $GPATH/tpl/css/wallets_balance.css $WEBPATH/css/ cp $GPATH/tpl/js/wallets_balance.js $WEBPATH/js/ cp $GPATH/tpl/wallets_balance.html $WEBPATH/data/wallets_balance.html -sort -Vr <<<"$htmlBloc" > /tmp/solde_g1_html.txt +sort -Vr <<<"$htmlBloc" | awk '{ print ""NR""$0"" ; }' > /tmp/solde_g1_html.txt printf '%s\n' '/_LINE/r /tmp/solde_g1_html.txt' 1 '/_LINE/d' w | ed $WEBPATH/data/wallets_balance.html > /dev/null sed -i "0,/_DATE/s//$(date '+%d-%m-%Y')/" $WEBPATH/data/wallets_balance.html rm /tmp/solde_g1_html.txt diff --git a/tpl/css/wallets_balance.css b/tpl/css/wallets_balance.css index c67c80f..09ac472 100644 --- a/tpl/css/wallets_balance.css +++ b/tpl/css/wallets_balance.css @@ -47,7 +47,6 @@ body { /* Add a grey background color to the table header and on hover */ background-color: #B69776; cursor: pointer; - position: sticky; top: 0px; } diff --git a/tpl/wallets_balance.html b/tpl/wallets_balance.html index d95b5e7..b1d562f 100644 --- a/tpl/wallets_balance.html +++ b/tpl/wallets_balance.html @@ -10,7 +10,7 @@ - + _LINE
Solde (Ḡ1)Clé publiqueIdentifiant utilisateur
PositionSolde (Ḡ1)Clé publiqueIdentifiant utilisateur