#!/bin/bash # Récupération du chemin absolut du répertoir du script actuel GPATH="$( cd "$(dirname "$0")" ; pwd -P )/.." [[ ! -f $GPATH/.env ]] && cp $GPATH/.env.example $GPATH/.env source $GPATH/.env timeout=320 startLoop=$(date +%s) echo "### $(date +%d-%m-%y) ###" # Exit if script is already alive if pidof -o %PPID -x "geoloc-members-json.sh">/dev/null; then echo "Process already running" exit 1 fi FILE="/tmp/geoloc-members.json" FINAL_LOCATION="$WEBPATH/data/geoloc-members.json" FINAL_LOCATION_ALT="$WEBPATH/data/geoloc-members-alt.json" echo "Get wallets list" DATA_MBR=$($JAKLIS listWallets --brut --mbr) DATA_NONMBR=$($JAKLIS listWallets --brut --non_mbr) DATA_LARF=$($JAKLIS listWallets --brut --larf) echo "{\"wallets\":[" > $FILE echo "Start loop membres" oldIFS=$IFS; IFS=$'\n'; j=0 for i in $DATA_MBR; do IFS=$oldIFS # [[ $((`date +%s`-$startLoop)) -ge 72000 ]] && echo "ERROR: spent more than 20h ... exit." && exit 1 pubkey=$(echo $i | awk '{ print $1 }') userId=\"$(echo $i | awk '{ print $2 }')\" result=$(timeout $timeout $JAKLIS get -p $pubkey) [[ $? -eq 124 ]] && echo "timeout $pubkey..." && continue geoPoint=$(echo "$result" | jq .geoPoint 2>/dev/null) if [[ "$geoPoint" == "null" || "$result" == "Profile vide" ]]; then continue else isMbr='"isMember": true,' userIdFormat="\"userId\": $userId," resultWithMbr=$(echo "$result" | sed "s/\"geoPoint\": {/$userIdFormat $isMbr \"geoPoint\": {/g") echo "$resultWithMbr," >> $FILE fi [[ $DEBUG ]] && echo "$j - $i" # [[ $DEBUG && $j -ge 5 ]] && break ((j++)) done echo "Start non membres loop" IFS=$'\n' for i in $DATA_NONMBR; do IFS=$oldIFS # [[ $((`date +%s`-$startLoop)) -ge 72000 ]] && echo "ERROR: spent more than 20h ... exit." && exit 1 pubkey=$(echo $i | awk '{ print $1 }') userId=\"$(echo $i | awk '{ print $2 }')\" result=$(timeout $timeout $JAKLIS get -p $pubkey) [[ $? -eq 124 ]] && echo "timeout $pubkey..." && continue geoPoint=$(echo "$result" | jq .geoPoint 2>/dev/null) if [[ "$geoPoint" == "null" || "$result" == "Profile vide" ]]; then continue else isMbr='"isMember": false,' userIdFormat="\"userId\": $userId," resultWithMbr=$(echo "$result" | sed "s/\"geoPoint\": {/$userIdFormat $isMbr \"geoPoint\": {/g") echo "$resultWithMbr," >> $FILE fi [[ $DEBUG ]] && echo "$j - $i" # [[ $DEBUG && $j -ge 7 ]] && break ((j++)) done echo "Start larfeuil loop" for i in $DATA_LARF; do # [[ $((`date +%s`-$startLoop)) -ge 72000 ]] && echo "ERROR: spent more than 20h ... exit." && exit 1 result=$(timeout $timeout $JAKLIS get -p $i) [[ $? -eq 124 ]] && echo "timeout $i" && continue geoPoint=$(echo "$result" | jq .geoPoint 2>/dev/null) if [[ "$geoPoint" == "null" || "$result" == "Profile vide" ]]; then continue else isMbr='"isMember": false,' resultWithMbr=$(echo "$result" | sed "s/\"geoPoint\": {/$isMbr \"geoPoint\": {/g") echo "$resultWithMbr," >> $FILE fi [[ $DEBUG ]] && echo "$j - $i" # [[ $DEBUG && $j -ge 10 ]] && break ((j++)) done nowD=$(date +"%s") sed -i '$ d' $FILE echo "}]," >> $FILE echo "\"time\": $nowD" >> $FILE echo "}" >> $FILE echo "Parse end result with jq" finalResult=$(cat $FILE | sed "/^,/Id" | jq .) RESULT=$? if [ $RESULT -eq 0 ]; then echo "$finalResult" > $FINAL_LOCATION else echo "Failed" >> $FILE fi echo "---"