-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutbid
executable file
·24 lines (21 loc) · 1.23 KB
/
outbid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#! /bin/bash
#echo "Starting outbid."
tosend=""
cp /data/bidding.csv /data/bidding_last.csv
space-cli listspaces | jq '.[] | select(.space.covenant.type == "bid" and .space.covenant.claim_height != null ) | {"name":.space.name,"claim":.space.covenant.claim_height,"bid":.space.covenant.total_burned}' | jq -s '.' | jq -r '(map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $cols, $rows[] | @csv' > /data/bidding.csv
#The following line is for testing
#cp /data/bidding_l.csv /data/bidding_last.csv
diff /data/bidding.csv /data/bidding_last.csv | grep "-" | grep -v -e "---" | grep -v -e "@@" > /data/outbid.csv
if [[ -s /data/outbid.csv ]]; then
tosend+="You were outbid! "
tosend+=$(cat /data/outbid.csv | tr -d '"' | tr -d '\n')
else
tosend+="All your bids are winning!"
fi
#echo '"'"$tosend"'"'
curl --request POST \
--url https://api.sendgrid.com/v3/mail/send \
--header "Authorization: Bearer $SENDGRID_API_KEY" \
--header 'Content-Type: application/json' \
--data '{"personalizations": [{"to": [{"email": "[email protected]"}]}],"from": {"email": "[email protected]"},"subject": "Bidding Report","content": [{"type": "text/plain", "value": "'"$tosend"'"}]}'
#echo "Ending outbid."