forked from axiom-team/astroport
74 lines
3.1 KiB
Bash
Executable File
74 lines
3.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 last ads
|
|
# Thank you @kimamila for cesium & gchange
|
|
# ES backend http://www.elasticsearchtutorial.com/spatial-search-tutorial.html
|
|
|
|
ipfsnodeid=$(ipfs id -f='<id>\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 'tail -f ~/.zen/cache/gchange.txt'
|
|
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/cache/gchange/$gID.json ]] && 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 \
|
|
&& sleep $((1 + RANDOM % 3))
|
|
|
|
creationTime=$(cat ~/.zen/cache/gchange/$gID.json | jq -r ._source.creationTime)
|
|
title=$(cat ~/.zen/cache/gchange/$gID.json | jq -r ._source.title)
|
|
currency=$(cat ~/.zen/cache/gchange/$gID.json | jq -r ._source.currency)
|
|
price=$(cat ~/.zen/cache/gchange/$gID.json | jq -r ._source.price)
|
|
[[ $price == null ]] && price="A débattre" || price=$(bc -l <<< "scale=2; $price / 100")
|
|
|
|
categoryname=$(cat ~/.zen/cache/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)"'"}'
|