g1-stats/scripts/geoloc-members-json.sh

121 lines
3.4 KiB
Bash
Raw Normal View History

#!/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=120
startLoop=$(date +%s)
echo "### $(date +%d-%m-%y) ###"
2022-05-15 17:33:14 +02:00
# 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"
2021-03-30 19:11:05 +02:00
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)
2021-10-14 21:56:20 +02:00
DATA_NONMBR=$($JAKLIS listWallets --brut --non_mbr)
DATA_LARF=$($JAKLIS listWallets --brut --larf)
2021-03-30 17:09:15 +02:00
2022-03-30 01:21:24 +02:00
echo "{\"wallets\":[" > $FILE
echo "Start loop membres"
oldIFS=$IFS;
IFS=$'\n';
2021-10-14 21:56:20 +02:00
j=0
2021-03-30 17:09:15 +02:00
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
2021-03-30 17:09:15 +02:00
isMbr='"isMember": true,'
2021-03-31 15:09:02 +02:00
userIdFormat="\"userId\": $userId,"
resultWithMbr=$(echo "$result" | sed "s/\"geoPoint\": {/$userIdFormat $isMbr \"geoPoint\": {/g")
2021-03-30 17:09:15 +02:00
echo "$resultWithMbr," >> $FILE
fi
[[ $DEBUG ]] && echo "$j - $i"
2022-03-30 01:21:24 +02:00
# [[ $DEBUG && $j -ge 5 ]] && break
((j++))
2021-03-30 17:09:15 +02:00
done
2021-10-14 21:56:20 +02:00
echo "Start non membres loop"
2021-10-14 21:56:20 +02:00
IFS=$'\n'
for i in $DATA_NONMBR; do
IFS=$oldIFS
[[ $((`date +%s`-$startLoop)) -ge 72000 ]] && echo "ERROR: spent more than 20h ... exit." && exit 1
2021-10-14 21:56:20 +02:00
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
2021-10-14 21:56:20 +02:00
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"
2022-03-30 01:21:24 +02:00
# [[ $DEBUG && $j -ge 7 ]] && break
((j++))
2021-10-14 21:56:20 +02:00
done
echo "Start larfeuil loop"
2021-03-30 17:09:15 +02:00
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
2021-03-30 17:09:15 +02:00
geoPoint=$(echo "$result" | jq .geoPoint 2>/dev/null)
2021-03-30 17:09:15 +02:00
if [[ "$geoPoint" == "null" || "$result" == "Profile vide" ]]; then
continue
else
isMbr='"isMember": false,'
2021-03-30 19:11:05 +02:00
resultWithMbr=$(echo "$result" | sed "s/\"geoPoint\": {/$isMbr \"geoPoint\": {/g")
2021-03-30 17:09:15 +02:00
echo "$resultWithMbr," >> $FILE
fi
[[ $DEBUG ]] && echo "$j - $i"
2022-03-30 01:21:24 +02:00
# [[ $DEBUG && $j -ge 10 ]] && break
((j++))
done
nowD=$(date +"%s")
sed -i '$ d' $FILE
2022-03-30 01:21:24 +02:00
echo "}]," >> $FILE
echo "\"time\": $nowD" >> $FILE
2022-03-30 01:21:24 +02:00
echo "}" >> $FILE
echo "Parse end result with jq"
2021-06-04 01:40:42 +02:00
finalResult=$(cat $FILE | jq .)
RESULT=$?
2021-03-31 15:09:02 +02:00
2021-06-04 01:40:42 +02:00
if [ $RESULT -eq 0 ]; then
echo "$finalResult" > $FINAL_LOCATION
2021-06-04 01:40:42 +02:00
else
echo "Failed" >> $FILE
fi
echo "---"