2021-09-12 19:27:12 +02:00
|
|
|
#!/bin/bash
|
|
|
|
########################################################################
|
|
|
|
# Author: Astrocrew
|
|
|
|
# Version: 0.1
|
|
|
|
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
|
|
|
########################################################################
|
|
|
|
MY_PATH="`dirname \"$0\"`" # relative
|
|
|
|
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
|
|
|
ME="${0##*/}"
|
|
|
|
countMErunning=$(ps auxf --sort=+utime | grep -w $ME | grep -v -E 'color=auto|grep' | wc -l)
|
|
|
|
[[ $countMErunning -gt 2 ]] && echo "$ME already running $countMErunning time" && exit 0
|
|
|
|
|
|
|
|
YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) && [[ ! $YOU ]] && echo "ipfs NOT RUNNING. EXIT" && exit 1
|
|
|
|
G1PUB=$(cat ~/.zen/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2) && [[ ! $G1PUB ]] && echo "NO ~/.zen/secret.dunikey EXIT" && exit 1
|
2021-09-13 00:53:49 +02:00
|
|
|
IPFSNODEID=$(ipfs --timeout=20s id -f='<id>\n' 2>/dev/null) && [[ $IPFSNODEID == "" ]] && echo 'NO IPFS RUNNING. EXIT' && exit 1
|
|
|
|
[ ! -d ~/.zen/ipfs/.$IPFSNODEID/astroport ] && echo 'ASTROPORT NOT READY' && exit 1
|
2021-09-12 19:27:12 +02:00
|
|
|
|
2021-09-13 00:53:49 +02:00
|
|
|
##############################################################"
|
|
|
|
## Backing up europa p4n collected spots from collective intelligence ##
|
|
|
|
# SWARM is collectively PLAYing bataille navale
|
|
|
|
# Randomly get geaodata in south europe
|
|
|
|
# FOCUS on SOUTH EUROPE
|
|
|
|
# LON = -10 to 30
|
|
|
|
# LAT = 35 to 60
|
|
|
|
# https://fr.mapsofworld.com/lat_long/europe.html
|
|
|
|
##############################################################"
|
|
|
|
# initial first spot.
|
2021-09-12 19:27:12 +02:00
|
|
|
lon=0
|
|
|
|
lat=40
|
2021-09-13 00:53:49 +02:00
|
|
|
try=1
|
|
|
|
|
|
|
|
# Randomly choose spot from in RANGE $lat.$lon
|
|
|
|
while [[ $(ls ~/.zen/ipfs_swarm/.*/astroport/map/$lat.$lon/p4n/spot.json 2>/dev/null) ]]; do
|
2021-09-12 19:27:12 +02:00
|
|
|
echo "astroport/$lat.$lon geodata already swarm captured. CONTINUE"
|
2021-09-13 22:54:33 +02:00
|
|
|
FLOOR=-5; #-10;
|
|
|
|
CEILING=10; #30
|
2021-09-12 19:27:12 +02:00
|
|
|
RANGE=$(($CEILING-$FLOOR+1));
|
|
|
|
RESULT=$RANDOM;
|
|
|
|
let "RESULT %= $RANGE";
|
|
|
|
lon=$(($RESULT+$FLOOR));
|
|
|
|
#echo $lon
|
|
|
|
|
2021-09-13 22:54:33 +02:00
|
|
|
FLOOR=40; #35;
|
|
|
|
CEILING=50; #60;
|
2021-09-12 19:27:12 +02:00
|
|
|
RANGE=$(($CEILING-$FLOOR+1));
|
|
|
|
RESULT=$RANDOM;
|
|
|
|
let "RESULT %= $RANGE";
|
|
|
|
lat=$(($RESULT+$FLOOR));
|
|
|
|
#echo $lat
|
2021-09-13 00:53:49 +02:00
|
|
|
try=$(($try+1));
|
|
|
|
[ $try -eq 99 ] && break ## tirages aléatoire maximum
|
2021-09-12 19:27:12 +02:00
|
|
|
done
|
|
|
|
|
2021-09-13 00:53:49 +02:00
|
|
|
##############################################################"
|
|
|
|
## $lat.$lon GEODATA NOT SCRAPED YET ?
|
|
|
|
##############################################################"
|
|
|
|
if [ ! -d ~/.zen/ipfs/.$IPFSNODEID/astroport/map/$lat.$lon/p4n/ ]; then
|
|
|
|
### ADD Spot randomness
|
|
|
|
# Fuzzle geoloc
|
|
|
|
one=$(echo "000$RANDOM$RANDOM$RANDOM" | cut -b1-12)
|
|
|
|
latitude="$lat.$one"
|
|
|
|
two=$(echo "000$RANDOM$RANDOM$RANDOM" | cut -b1-12)
|
|
|
|
longitude="$lon.$two"
|
2021-09-12 19:27:12 +02:00
|
|
|
|
|
|
|
### SCRAPE P4N
|
2021-09-13 00:53:49 +02:00
|
|
|
## curl spot.json into /astroport/map/$lat.$lon/p4n/spot.json
|
2021-09-12 19:27:12 +02:00
|
|
|
echo "GETTING /astroport/map/$lat.$lon/p4n/spot.json"
|
|
|
|
mkdir -p ~/.zen/ipfs/.$IPFSNODEID/astroport/map/$lat.$lon/p4n/
|
|
|
|
echo "https://www.park4night.com/services/V3/getLieuxAroundMeLite.php?latitude=$latitude&longitude=$longitude"
|
|
|
|
curl -s "https://www.park4night.com/services/V3/getLieuxAroundMeLite.php?latitude=$latitude&longitude=$longitude" -o ~/.zen/ipfs/.$IPFSNODEID/astroport/map/$lat.$lon/p4n/spot.json
|
|
|
|
echo "SAVED ~/.zen/ipfs/.$IPFSNODEID/astroport/map/$lat.$lon/p4n/spot.json"
|
2021-09-13 00:53:49 +02:00
|
|
|
## TODO REFRESH OLD spot.json
|
|
|
|
fi
|
|
|
|
|
|
|
|
##############################################################"
|
|
|
|
## GEODATA. continue. Let's extract lieu pdf from my spot
|
|
|
|
##############################################################"
|
|
|
|
geodata=$(ls ~/.zen/{ipfs,ipfs_swarm}/.*/astroport/map/$lat.$lon/p4n/spot.json 2>/dev/null | tail -n 1)
|
2021-09-13 18:15:25 +02:00
|
|
|
ipfsnodeid=$(echo "$geodata" | cut -d '/' -f 6 | cut -d '.' -f 2)
|
2021-09-13 00:53:49 +02:00
|
|
|
|
|
|
|
if [[ "$ipfsnodeid" != "$IPFSNODEID" ]]; then
|
|
|
|
echo "This spot.json is already managed by $ipfsnodeid"
|
|
|
|
echo "getting one for mine"
|
|
|
|
geodata=$(ls ~/.zen/ipfs/.*/astroport/map/*.*/p4n/spot.json | shuf | tail -n 1)
|
|
|
|
fi
|
|
|
|
|
|
|
|
[[ $geodata ]] && ipfsnodeid=$(echo "$geodata" | cut -d '/' -f 6 | cut -d '.' -f 2) || exit 1
|
|
|
|
|
|
|
|
## SUB-SCRAPE SOME of my p4n/spot.json RANDOM "lieu"
|
|
|
|
echo "SUB-SCRAPING lieu FROM /astroport/map/$lat.$lon/p4n/spot.json"
|
|
|
|
|
|
|
|
loop=1
|
|
|
|
while [ $loop -lt 21 ]; do
|
|
|
|
#{"id":"208264","latitude":"40.730727","longitude":"0.367303","hauteur_limite":"0.00","publique":"1","top_liste":"0","code":"APN","validation_admin":"1","distance":"97.341"}
|
|
|
|
# flatten json
|
|
|
|
|
|
|
|
lieu=$(cat $geodata | jq -r '.lieux[] | "\(.id),\(.latitude),\(.longitude),\(.hauteur_limite),\(.publique),\(.top_liste),\(.code),\(.validation_admin),\(.distance)"' | shuf | tail -n 1)
|
2021-09-13 18:36:24 +02:00
|
|
|
## GET RANDOM LIEU ID AND TRY MORE TO GET ( prefered APN)
|
|
|
|
lid=$(echo "$lieu" | cut -d ',' -f 1); code=$(echo "$lieu" | cut -d ',' -f 7)
|
|
|
|
[[ "$code" != "APN" ]] && [ -d ~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid ] && lieu=$(cat $geodata | jq -r '.lieux[] | "\(.id),\(.latitude),\(.longitude),\(.hauteur_limite),\(.publique),\(.top_liste),\(.code),\(.validation_admin),\(.distance)"' | shuf | tail -n 1)
|
|
|
|
lid=$(echo "$lieu" | cut -d ',' -f 1); code=$(echo "$lieu" | cut -d ',' -f 7)
|
|
|
|
[[ "$code" != "APN" ]] && [ -d ~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid ] && lieu=$(cat $geodata | jq -r '.lieux[] | "\(.id),\(.latitude),\(.longitude),\(.hauteur_limite),\(.publique),\(.top_liste),\(.code),\(.validation_admin),\(.distance)"' | shuf | tail -n 1)
|
|
|
|
lid=$(echo "$lieu" | cut -d ',' -f 1); code=$(echo "$lieu" | cut -d ',' -f 7)
|
|
|
|
[[ "$code" != "APN" ]] && [ -d ~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid ] && lieu=$(cat $geodata | jq -r '.lieux[] | "\(.id),\(.latitude),\(.longitude),\(.hauteur_limite),\(.publique),\(.top_liste),\(.code),\(.validation_admin),\(.distance)"' | shuf | tail -n 1)
|
|
|
|
lid=$(echo "$lieu" | cut -d ',' -f 1); code=$(echo "$lieu" | cut -d ',' -f 7)
|
2021-09-13 00:53:49 +02:00
|
|
|
[ -d ~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid ] && lieu=$(cat $geodata | jq -r '.lieux[] | "\(.id),\(.latitude),\(.longitude),\(.hauteur_limite),\(.publique),\(.top_liste),\(.code),\(.validation_admin),\(.distance)"' | shuf | tail -n 1)
|
2021-09-13 18:36:24 +02:00
|
|
|
lid=$(echo "$lieu" | cut -d ',' -f 1); code=$(echo "$lieu" | cut -d ',' -f 7)
|
2021-09-13 00:53:49 +02:00
|
|
|
[ -d ~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid ] && lieu=$(cat $geodata | jq -r '.lieux[] | "\(.id),\(.latitude),\(.longitude),\(.hauteur_limite),\(.publique),\(.top_liste),\(.code),\(.validation_admin),\(.distance)"' | shuf | tail -n 1)
|
2021-09-13 18:36:24 +02:00
|
|
|
lid=$(echo "$lieu" | cut -d ',' -f 1); code=$(echo "$lieu" | cut -d ',' -f 7)
|
2021-09-13 00:53:49 +02:00
|
|
|
|
2021-09-13 03:16:43 +02:00
|
|
|
[[ "$lid" == "" ]] && continue
|
2021-09-13 00:53:49 +02:00
|
|
|
|
|
|
|
if [[ $(which chromium) ]]; then
|
|
|
|
mkdir -p /tmp/$lid && cd /tmp/$lid
|
2021-09-13 18:14:11 +02:00
|
|
|
echo "Downloading https://www.park4night.com/?page=lieu&id=$lid&bulle=YES"
|
2021-09-13 00:53:49 +02:00
|
|
|
mkdir -p ~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid/$code
|
|
|
|
echo "id,latitude,longitude,hauteur_limite,publique,top_liste,code,validation_admin,distance" > ~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid/$code/lieu.txt
|
|
|
|
echo "$lieu" >> ~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid/$code/lieu.txt
|
|
|
|
|
2021-09-13 02:44:25 +02:00
|
|
|
[ ! -f ~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid/bulle.pdf ] && chromium --timeout=30000 --headless --no-sandbox --disable-gpu --print-to-pdf=output.pdf "https://www.park4night.com/?page=lieu&id=$lid&bulle=YES" 2>/dev/null
|
|
|
|
[ ! -f ./output.pdf ] && rm -Rf ~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid
|
|
|
|
[ -f ./output.pdf ] && mv ./output.pdf ~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid/bulle.pdf
|
|
|
|
|
2021-09-13 02:29:23 +02:00
|
|
|
echo "~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid/bulle.png"
|
2021-09-13 00:53:49 +02:00
|
|
|
sleep $((1 + RANDOM % 2))
|
|
|
|
cd - && rm -Rf /tmp/$lid
|
|
|
|
|
|
|
|
# TODO FUTURE BATCH to convert & crop to jpg image (imagemagick)
|
|
|
|
# convert -density 300 -depth 8 -quality 90 -trim ./output.pdf ./output.jpg
|
|
|
|
else
|
|
|
|
sudo apt-get install chromium -y
|
|
|
|
fi
|
|
|
|
loop=$(($loop+1));
|
|
|
|
done
|
|
|
|
|
2021-09-13 18:10:35 +02:00
|
|
|
## CHECK SWARM GEODATA MAP
|
|
|
|
# ls -d ~/.zen/ipfs_swarm/.*/astroport/map/*/ | rev | cut -d '/' -f 2 | rev | sort
|
|
|
|
## NB OF lieu: ls -d ~/.zen/ipfs_swarm/.*/astroport/map/p4n/lieu/*/ | rev | cut -d '/' -f 2 | rev | sort | wc
|
2021-09-13 00:53:49 +02:00
|
|
|
# ipfs cat /ipns/$IPFSNODEID/.$IPFSNODEID/astroport/map/$lat.$lon/p4n/spot.json | jq
|
2021-09-12 19:27:12 +02:00
|
|
|
exit 0
|