diff --git a/zen/tools/gchange_MAP.sh b/zen/tools/gchange_MAP.sh new file mode 100755 index 0000000..038b90f --- /dev/null +++ b/zen/tools/gchange_MAP.sh @@ -0,0 +1,92 @@ +#!/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##*/}" +######################################################################## +LON=$1 +LAT=$2 + +[[ ! ( $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 +# 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') + +RAD="$1" +[[ ! $RAD ]] && RAD="25km" + +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) +chunk=0 +fullcount=0 + +for gID in $(cat /tmp/gchange.json | jq -r .hits.hits[]._id); do + + NEW="" + + 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 + + ## ISSUER DE L'AUTEUR DE L'ANNONCE + 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,type,geoPoint + ISSUER=$(cat ~/.zen/.cache/gchange/$gID.json | jq -r ._source.issuer) + + ## SOCIAL DE L'AUTEUR DE L'ANNONCE + curl -s --create-dirs -o ~/.zen/.cache/gchange/profil.$ISSUER.json -s https://data.gchange.fr/user/profile/$ISSUER?&_source_exclude=avatar._content + SOCIAL=$(cat ~/.zen/.cache/gchange/profil.$ISSUER.json | jq -r ._source.socials) + + ## G1KEY DE L'AUTEUR DE L'ANNONCE + G1KEY=$(cat ~/.zen/.cache/gchange/profil.$ISSUER.json | jq -r ._source.pubkey) + + ## LIEN CESIUM + + if [[ $G1KEY != "" ]]; then + curl -s --create-dirs -o ~/.zen/.cache/g1profil.$G1KEY.json -s https://g1.data.le-sou.org/user/profile/$G1KEY + title=$(cat ~/.zen/.cache/g1profil.$ISSUER.json | jq -r ._source.title) + address=$(cat ~/.zen/.cache/g1profil.$ISSUER.json | jq -r ._source.address) + socials=$(cat ~/.zen/.cache/g1profil.$ISSUER.json | jq -r ._source.socials) + city=$(cat ~/.zen/.cache/g1profil.$ISSUER.json | jq -r ._source.city) + geoPoint=$(cat ~/.zen/.cache/g1profil.$ISSUER.json | jq -r ._source.geoPoint) + echo "$title - $address - $city" >> ~/.zen/.cache/gchange.txt + echo "$title - $address - $city" + echo $socials | jq -r + echo $geoPoint | jq -r + fi + sleep $((1 + RANDOM % 3)) + fi +done +cat ~/.zen/.cache/gchange.txt