actions/p4n.swarmscraper.sh

This commit is contained in:
fred 2021-09-13 00:53:49 +02:00
parent 31f16240ee
commit 25275d3d1e
2 changed files with 92 additions and 14 deletions

View File

@ -12,14 +12,25 @@ countMErunning=$(ps auxf --sort=+utime | grep -w $ME | grep -v -E 'color=auto|gr
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
IPFSNODEID=$(ipfs --timeout=20s id -f='<id>\n') && [[ ! $IPFSNODEID ]] && echo 'NO IPFS RUNNING. EXIT' && exit 1
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
## Backing up europa p4n collected from collective intelligence spots
# PLAY bataille navale
# Randomly get geaodata in longitude -10 to 30 / lat from 35 to 60 square
##############################################################"
## 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.
lon=0
lat=40
while $(ls ~/.zen/ipfs_swarm/.*/astroport/$lat.$lon/p4n 2>/dev/null); do
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
echo "astroport/$lat.$lon geodata already swarm captured. CONTINUE"
FLOOR=-10;
CEILING=30;
@ -36,25 +47,91 @@ while $(ls ~/.zen/ipfs_swarm/.*/astroport/$lat.$lon/p4n 2>/dev/null); do
let "RESULT %= $RANGE";
lat=$(($RESULT+$FLOOR));
#echo $lat
try=$(($try+1));
[ $try -eq 99 ] && break ## tirages aléatoire maximum
done
### ADD Spot random
# Add random ness
one=$(echo "00$RANDOM$RANDOM$RANDOM" | cut -b1-12)
latitude="$lat.$one"
two=$(echo "00$RANDOM$RANDOM$RANDOM" | cut -b1-12)
longitude="$lon.$two"
##############################################################"
## $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"
### SCRAPE P4N
## Copy spot.json into astroport geodata directories
## curl spot.json into /astroport/map/$lat.$lon/p4n/spot.json
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"
## 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)
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)
## GET RANDOM LIEU ID AND TRY MORE
lid=$(echo "$lieu" | cut -d ',' -f 1)
[ -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)
[ -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)
[ -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)
[ -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)
if [[ $(which chromium) ]]; then
mkdir -p /tmp/$lid && cd /tmp/$lid
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
[ ! -f ~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid/bulle.pdf ] && chromium --headless --no-sandbox --print-to-pdf "https://www.park4night.com/?page=lieu&id=$lid&bulle=YES" 2>/dev/null
[ -f ./output.pdf ] && mv ./output.pdf ~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid/bulle.pdf
echo "~/.zen/ipfs/.$IPFSNODEID/astroport/map/p4n/lieu/$lid/bulle.pdf"
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
##############################################################"
# IPNS SELF PUBLISH = mise à jour balise Station
########################################################################
~/.zen/astrXbian/zen/ipns_self_publish.sh
########################################################################
# ipfs cat /ipns/$IPFSNODEID/.$IPFSNODEID/astroport/map/$lat.$lon/p4n/spot.json | jq
exit 0

View File

@ -339,7 +339,8 @@ echo "</main></body></html>" >> ~/.zen/ipfs/.${IPFSNODEID}/FRIENDS/index.html
# IPNS SELF PUBLISH = mise à jour balise Station
########################################################################
~/.zen/astrXbian/zen/ipns_self_publish.sh
#~/.zen/astrXbian/zen/ipns_self_publish.sh
########################################################################
~/.zen/astrXbian/actions/p4n.swarmscraper.sh
exit 0