-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
33 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
||
|
@@ -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 | ||
# | ||
|