Skip to content

Commit

Permalink
script file for v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
steppsr authored Jul 22, 2022
1 parent b8d0200 commit 8d80cc2
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions nftmon/nftmon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@

# NFT Monitor

# USER CONFIG SECTION ==========================================================================
email="[email protected]"
wallet_id="10"
# END USER CONFIG ==============================================================================


# ------------------------------------------------------------------------
# All configuration settings should be changed ABOVE, not below this line.
# ------------------------------------------------------------------------
email=$1
appdir=`pwd`

# Activate Chia python environment
cd ~/chia-blockchain
. ./activate
cd $appdir

# Get a list of all NFT wallets
wallet_list=`chia wallet show -w nft | grep "Wallet ID" | cut --fields 2 --delimiter=: | xargs`

# Default starting values
lastnftcount=0
nftcount=0
Expand All @@ -36,11 +31,27 @@ if [ $history_exists == "false" ]; then
fi

# Calculate the current number of NFTs in the wallet specified in the USER CONFIG SECTION
nftcount=`chia wallet nft list -i $wallet_id | grep "NFT identifier" | wc -l`
temp=0
for val in $wallet_list; do
temp=`chia wallet nft list -i $val | grep "NFT identifier" | wc -l`
nftcount=$(($nftcount+$temp))
done

# Gather all the URIs for the data
nfturis=$(chia rpc wallet nft_get_nfts '{"wallet_id": '\"$wallet_id\"'}' | jq '.nft_list[].data_uris[0]' | cut --fields 2 --delimiter=\")
printf "$nfturis\n" > $appdir/.currenturis
echo "" > $appdir/.currenturis
nfturis=""
monchia_nfts=""
for val in $wallet_list; do
tempuris=$(chia rpc wallet nft_get_nfts '{"wallet_id": '\"$val\"'}' | jq '.nft_list[].data_uris[0]' | cut --fields 2 --delimiter=\")
if ! [ -z "$tempuris" ]; then
nfturis="$nfturis $tempuris"
tempuris=""
else
tempuris=""
fi
done
nfturis=`echo $nfturis | tr ' ' '\n'`
printf '%s' "${nfturis}" > $appdir/.currenturis
grep -Fxvf $appdir/.nfturis $appdir/.currenturis > $appdir/.newuris
rm $appdir/.currenturis

Expand All @@ -49,23 +60,28 @@ if test -f "$appdir/.nftcount"; then
lastnftcount=`cat $appdir/.nftcount`
fi

( while read url; do echo "<a href='$url'><img src='$url' width='100px' height='100px'</a>"; done < $appdir/.newuris ) > $appdir/.newurls.html
( while read url; do echo "<a href='$url'><img src='$url' width='100px' height='100px'></a>"; done < $appdir/.newuris ) > $appdir/.newurls.html
newuris=`cat $appdir/.newurls.html`

# Send email if the current number of NFTs is different from the value in our history file.
email_template="From: $email\r\nDate: $(date)\r\nSubject: New NFT in Wallet\r\nMIME-Version: 1.0\r\nContent-Type: text/html; charset=utf-8\r\n\r\n<h3>Congratulations! You have a new NFT in your wallet.</h3><br>$newuris\n"
#email_template="From: $email\r\nDate: $(date)\r\nSubject: New NFT in Wallet\r\nMIME-Version: 1.0\r\nContent-Type: text/html; charset=utf-8\r\n\r\n<h3>Congratulations! You have a new NFT in your wallet.</h3><br>$newuris\n"

email_body="<h3>Congratulations! You have a new NFT in your wallet.</h3><br>$newuris"
echo $email_body > $appdir/.nftemail.html
email_subject="New NFT in Wallet"
if [ "$nftcount" != "$lastnftcount" ]; then
printf "$email_template" | /usr/sbin/ssmtp $email
#printf "$email_template" | /usr/sbin/ssmtp $email
mailx -a 'Content-Type: text/html' -s "$email_subject" < $appdir/.nftemail.html "$email"
fi

# Update out history files so they are ready for the next time the script runs.
echo $nftcount > $appdir/.nftcount
printf "$nfturis\n" > $appdir/.nfturis
printf '%s' "${nfturis}" > $appdir/.nfturis

# Clean up temp files
rm $appdir/.newuris
rm $appdir/.newurls.html

rm $appdir/.nftemail.html

# Version History
#
Expand Down

0 comments on commit 8d80cc2

Please sign in to comment.