astrXbian/zen/tools/gchange_MAP.sh

118 lines
5.1 KiB
Bash
Executable File

#!/bin/bash
########################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
########################################################################
# Extract Gchange Ads
# Thank you @kimamila for cesium & gchange
# ES backend http://www.elasticsearchtutorial.com/spatial-search-tutorial.html
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
ME="${0##*/}"
########################################################################
LAT="$1"
LON="$2"
RAD="$3"
[[ ! $RAD ]] && RAD="25km"
[[ ! ( $LAT && $LON ) ]] && echo "Indiquez les coordonnées GPS et le rayon de votre recherche! ex: $ME 43.614208 1.4155776 50km" && exit 1
########################################################################
CESIUM="https://g1.data.le-sou.org"
GCHANGE="https://data.gchange.fr" # /user/profile/2L8vaYixCf97DMT8SistvQFeBj7vb6RQL7tvwyiv1XVH?&_source_exclude=avatar._content
[[ ! -d ~/.zen/.cache/gchange ]] && mkdir -p ~/.zen/.cache/gchange
rm ~/.zen/.cache/g1contact.txt
# curl -sk ${CESIUM}/user/profile/${g1pub} -o ~/.zen/.cache/cesium_profile.json
# LON=$(cat ~/.zen/.cache/cesium_profile.json | jq '._source.geoPoint.lon')
# LAT=$(cat ~/.zen/.cache/cesium_profile.json | jq '._source.geoPoint.lat')
# curl -sk ${GCHANGE}/user/profile/${g1pub} -o ~/.zen/.cache/GCHANGE_profile.json
# LON=$(cat ~/.zen/.cache/GCHANGE_profile.json | jq '._source.geoPoint.lon')
# LAT=$(cat ~/.zen/.cache/GCHANGE_profile.json | jq '._source.geoPoint.lat')
curl -sk -XPOST 'https://data.gchange.fr/market/record/_search?pretty&_source=title' -d '
{
"size": 200,
"query": {
"bool": {
"filter": [{
"geo_distance": {
"distance": "'$RAD'",
"geoPoint": {
"lat": '$LAT',
"lon": '$LON'
}
}
}]
}
}
}' > /tmp/gchange.json || exit 1
TIMESTAMP=$(date -u +"%s")
TOTAL=$(cat /tmp/gchange.json | jq .hits.total)
echo "##################################################################"
echo "$TOTAL ANNONCES A $RAD de $LAT $LON"
echo "##################################################################"
chunk=0
fullcount=0
for gID in $(cat /tmp/gchange.json | jq -r .hits.hits[]._id); do
NEW=""
echo "##################################################################"
if [[ ! -f ~/.zen/.cache/gchange/$gID.json ]]; then
NEW="true"
# curl -s --create-dirs -o ~/.zen/.cache/gchange/$gID.json -s https://data.gchange.fr/market/record/$gID?_source=category,title,description,issuer,time,creationTime,location,address,city,price,unit,currency,thumbnail._content_type,thumbnail._content,picturesCount,type,stock,fees,feesCurrency,geoPoint
## ANNONCE
curl -S -s --create-dirs -o ~/.zen/.cache/gchange/$gID.json -s "https://data.gchange.fr/market/record/$gID?_source=category,title,description,issuer,time,creationTime,location,address,city,price,unit,currency,type,geoPoint"
sleep 1
fi
## ISSUER DE L'ANNONCE
ISSUER=$(cat ~/.zen/.cache/gchange/$gID.json | jq -r ._source.issuer)
echo "ISSUER=$ISSUER"
## PROFIL CREATEUR DE L'ANNONCE
curl -S -s --create-dirs -o ~/.zen/.cache/gchange/profil.$ISSUER.json -s "https://data.gchange.fr/user/profile/$ISSUER?&_source_exclude=avatar._content"
Gtitle=$(cat ~/.zen/.cache/gchange/profil.$ISSUER.json | jq -r ._source.title)
Gaddress=$(cat ~/.zen/.cache/gchange/profil.$ISSUER.json | jq -r ._source.address)
Gcity=$(cat ~/.zen/.cache/gchange/profil.$ISSUER.json | jq -r ._source.city)
echo "GCONTACT $Gtitle - $Gaddress - $Gcity"
## G1KEY DE L'AUTEUR DE L'ANNONCE
G1KEY=$(cat ~/.zen/.cache/gchange/profil.$ISSUER.json | jq -r ._source.pubkey)
echo "G1KEY=$G1KEY"
## LIEN CESIUM +
if [[ $G1KEY != "null" && $G1KEY != "" ]]; then
curl -S -s --create-dirs -o ~/.zen/.cache/g1profil.$G1KEY.json -s "https://g1.data.le-sou.org/user/profile/$G1KEY?&_source_exclude=avatar._content"
[[ ! -f ~/.zen/.cache/g1profil.$G1KEY.json ]] && echo "RIEN SUR CESIUM" && continue
fi
[[ -f ~/.zen/.cache/g1contact.txt ]] && TEST=$(cat ~/.zen/.cache/g1contact.txt | grep $G1KEY)
if [[ "$TEST" == "" ]]
then
title=$(cat ~/.zen/.cache/g1profil.$G1KEY.json | jq -r ._source.title)
address=$(cat ~/.zen/.cache/g1profil.$G1KEY.json | jq -r ._source.address)
socials=$(cat ~/.zen/.cache/g1profil.$G1KEY.json | jq -r ._source.socials)
city=$(cat ~/.zen/.cache/g1profil.$G1KEY.json | jq -r ._source.city)
geoPoint=$(cat ~/.zen/.cache/g1profil.$G1KEY.json | jq -r ._source.geoPoint)
echo "##################################################################" >> ~/.zen/.cache/g1contact.txt
echo "$G1KEY" >> ~/.zen/.cache/g1contact.txt
echo "$title - $address - $city" >> ~/.zen/.cache/g1contact.txt
echo $socials >> ~/.zen/.cache/g1contact.txt
echo $geoPoint >> ~/.zen/.cache/g1contact.txt
echo "G1CONTACT $title - $address - $city"
echo $geoPoint
sleep $((1 + RANDOM % 3))
else
echo "DEJA CONNU"
fi
done
cat ~/.zen/.cache/g1contact.txt