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

67 lines
1.9 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
2021-03-30 17:09:15 +02:00
SOURCE_MBR="https://g1-stats.axiom-team.fr/data/wallets-g1-membres.txt"
SOURCE_LARF="https://g1-stats.axiom-team.fr/data/wallets-g1-simple.txt"
FILE="/tmp/geoloc-members.json"
2021-03-30 19:11:05 +02:00
FINAL_LOCATION="$WEBPATH/data/geoloc-members.json"
if [[ -f /home/axiom/apps/g1-stats/data/wallets-g1-membres.txt ]]; then
2021-03-30 17:09:15 +02:00
DATA_MBR=$(cat /home/axiom/apps/g1-stats/data/wallets-g1-membres.txt)
else
2021-03-30 17:09:15 +02:00
DATA_MBR=$(curl -s $SOURCE_MBR)
fi
if [[ -f /home/axiom/apps/g1-stats/data/wallets-g1-simple.txt ]]; then
DATA_LARF=$(cat /home/axiom/apps/g1-stats/data/wallets-g1-simple.txt)
else
DATA_LARF=$(curl -s $SOURCE_LARF)
fi
echo "[" > $FILE
2021-03-30 17:09:15 +02:00
for i in $DATA_MBR; do
2021-06-04 01:40:42 +02:00
result=$($JAKLIS get -p $i)
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-06-04 01:40:42 +02:00
userId=$($JAKLIS id -p $i | jq .idty.username)
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
2021-03-30 17:09:15 +02:00
done
for i in $DATA_LARF; do
2021-06-04 01:40:42 +02:00
result=$($JAKLIS get -p $i)
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
done
sed -i '$ d' $FILE
echo "}" >> $FILE
echo "]" >> $FILE
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
else
echo "Failed" >> $FILE
fi