From fcbbf0515da5482b16bdcaf268094aac39a09b4b Mon Sep 17 00:00:00 2001 From: qo-op Date: Sun, 3 May 2020 04:11:38 +0200 Subject: [PATCH] ## TODO AUTOMATIC PUBLISHING \n problem ?? --- zen/cron_MINUTE.sh | 2 +- zen/gchange_MONITOR.sh | 71 ++++++++++++++++++++++++++++++++++ zen/ssb_INIT.sh | 2 +- zen/tools/make_G1SSB_secret.sh | 3 ++ 4 files changed, 76 insertions(+), 2 deletions(-) create mode 100755 zen/gchange_MONITOR.sh diff --git a/zen/cron_MINUTE.sh b/zen/cron_MINUTE.sh index 6d8ddde..daedd0b 100755 --- a/zen/cron_MINUTE.sh +++ b/zen/cron_MINUTE.sh @@ -8,7 +8,7 @@ MY_PATH="`dirname \"$0\"`" # relative MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized ME="${0##*/}" -[[ $(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) ]] || echo "ipfs failure" && exit 1 +[[ $(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) ]] || echo "ipfs daemon not running. EXIT" && exit 1 ipfsnodeid=$(/usr/local/bin/ipfs id -f='\n') g1pub=$(cat ~/.ssb/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2) diff --git a/zen/gchange_MONITOR.sh b/zen/gchange_MONITOR.sh new file mode 100755 index 0000000..de26249 --- /dev/null +++ b/zen/gchange_MONITOR.sh @@ -0,0 +1,71 @@ +#!/bin/bash +################################################################################ +# Author: Fred (support@qo-op.com) +# Version: 0.1 +# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/) +################################################################################ +# Extract last ads +# Thank you @kimamila for cesium & gchange +# ES backend http://www.elasticsearchtutorial.com/spatial-search-tutorial.html + +ipfsnodeid=$(ipfs id -f='\n') +[[ ! -f ~/.ssb/secret.dunikey ]] && $MY_PATH/tools/secret2dunikey.sh +g1pub=$(cat ~/.ssb/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2) + +CESIUM="https://g1.data.le-sou.org" + +curl -sk ${CESIUM}/user/profile/${g1pub} -o /tmp/profile.json +LON=$(cat /tmp/profile.json | jq '._source.geoPoint.lon') +LAT=$(cat /tmp/profile.json | jq '._source.geoPoint.lat') + +RAD="$1" +[[ ! $RAD ]] && RAD="10km" + +if [[ "$LON" != "null" ]]; then +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 +else + echo "Aucune coordonnées geoPoint pour $g1pub" && exit 1 +fi +TIMEBEFORE=$(date -u --date="-$DELAY" +"%s") +TIMESTAMP=$(date -u +"%s") +TOTAL=$(cat /tmp/gchange.json | jq .hits.total) +echo '# #GCHANGE-Market' > ~/.zen/cache/gchange.txt +echo "> A $RAD de la [position](https://demo.cesium.app/#/app/wot/map) de mon [portefeuille](https://demo.cesium.app/#/app/wot/$g1pub/)" >> ~/.zen/cache/gchange.txt +chunk=0 +for gID in $(cat /tmp/gchange.json | jq -r .hits.hits[]._id); do + [[ -f ~/.zen/ipfs_swarm/gchange/$gID.json ]] && INSWARM="true" + NEW="" + [[ ! -f ~/.zen/ipfs/gchange/$gID.json ]] && NEW="true" \ + && curl -s --create-dirs -o ~/.zen/ipfs/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,picturesCount,type,stock,fees,feesCurrency,geoPoint \ + && sleep $((1 + RANDOM % 3)) + + creationTime=$(cat ~/.zen/ipfs/gchange/$gID.json | jq -r ._source.creationTime) + title=$(cat ~/.zen/ipfs/gchange/$gID.json | jq -r ._source.title) + currency=$(cat ~/.zen/ipfs/gchange/$gID.json | jq -r ._source.currency) + price=$(cat ~/.zen/ipfs/gchange/$gID.json | jq -r ._source.price) + [[ $price == null ]] && price="A débattre" + categoryname=$(cat ~/.zen/ipfs/gchange/$gID.json | jq -r ._source.category.name) + + [[ $NEW == "true" ]] && echo "- [$title](https://data.gchange.fr/market/record/$gID/_share) PRIX $price ($currency)" >> ~/.zen/cache/gchange.txt && chunk=$((chunk+1)) + +done +echo "$chunk nouvelles annonces ($TOTAL)" >> ~/.zen/cache/gchange.txt + +## TODO AUTOMATIC PUBLISHING \n problem ?? +# sbotc publish '{"type":"post","text":"'"$(cat ~/.zen/cache/gchange.txt)"'"}' diff --git a/zen/ssb_INIT.sh b/zen/ssb_INIT.sh index 04ef069..8fdafaa 100755 --- a/zen/ssb_INIT.sh +++ b/zen/ssb_INIT.sh @@ -99,7 +99,7 @@ sbot publish --type about --about $ssbpub --description "[Astroport Node](https: # REQUEST DUNITER G1 Wallet balance DUNITERNODE=$($MY_PATH/tools/duniter_getnode.sh) g1balance=$(silkaj -p $DUNITERNODE balance $g1pub 2>&1) -# SSB PUBLISH G1 wallet silkaj balance +# SSB PUBLISH G1 wallet silkaj balance # TODO crash bad text format sbotc publish '{"type":"post","text":"'"$g1balance"'"}' echo " diff --git a/zen/tools/make_G1SSB_secret.sh b/zen/tools/make_G1SSB_secret.sh index 1c0739d..eb288fd 100755 --- a/zen/tools/make_G1SSB_secret.sh +++ b/zen/tools/make_G1SSB_secret.sh @@ -31,6 +31,9 @@ HIT ENTER TO CONTINUE ' read letsgo +[[ $(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1) ]] || echo "ipfs daemon not running. EXIT" && exit 1 + + # git & astroport code in ~/.zen [[ ! -d ~/.zen/astroport ]] && mkdir -p ~/.zen/astroport