diff --git a/bash/scrapeMoonrank.sh b/bash/scrapeMoonrank.sh index 3d37921..b9724e8 100755 --- a/bash/scrapeMoonrank.sh +++ b/bash/scrapeMoonrank.sh @@ -4,6 +4,9 @@ # rarities for all NFTs of a collection (must be fully minted). ########## Configurable Variables ########## +# Where to save the json files # +# File location: (folder) # + directory="~" # # # How long to wait for a response # # Curl timeout: (seconds) # @@ -13,7 +16,7 @@ # Delay: (seconds) # delay=2 # # -# How many checks to do sequentially # +# How many checks to do between sleeps # # Count: (number) # sequential=2 # # @@ -32,6 +35,7 @@ max=0 cur=0 moonrank="https://moonrank.app/collection/" +trap ctrl_c INT function ctrl_c() { tput cnorm echo "${rst}${red}CTRL+C Detected, exiting.${rst}" @@ -74,22 +78,64 @@ function appendjson() { } function pad() { - seq -s " " $1 | tr -d "[:digit:]" + [ $1 -ne 0 ] && seq -s " " $1 | tr -d "[:digit:]" } -function tableheader() { - datasize=8 - [ ${#nftname} -gt $datasize ] && let datasize="${#nftname}-${datasize}" - echo -en " NFT ID " - +function isodd(){ + local num=$1 + [ $num -eq 0 ] && return 0 + [ $num -lt 0 ] && let num="num*-1" + local a=0;local b=0 + let a="num/2" + let b="(num-1)/2" + [ $a -eq $b ] && return 1 + return 0 +} +function tableheader() { + [ $didheader -eq 2 ] && return 1 + didheader=0 + local namelen=${#nftname} + isodd $namelen + local odd=$? + if [[ $namelen -gt 7 ]]; then + let prepost="namelen-7" + let prepost="prepost/2" + elif [[ $namelen -lt 7 ]]; then + let prepost="7-namelen" + let prepost="prepost/2" + else + prepost=0 + fi + + for i in `seq 2`; do + [ $didheader -eq 0 ] && echo -n " " + pad $prepost + [ $prepost -ne 0 ] && echo -n " " + echo -n "NFT ID" + [ $odd -eq 0 ] && let prepost="prepost+1" + pad $prepost + [ $prepost -eq 0 ] && echo -en "\t" + echo -en "\tNFT Rarity Rank" + [ $didheader -eq 0 ] && echo -en "\t\t" + [ $didheader -eq 1 ] && echo + let didheader="didheader+1" + done + tablecolumn=1 } -# $1=column1/3 $2=column2/4 $3=column1/2or3/4 -function tablebody() { - continue +function tablerow() { + if [[ $tablecolumn -eq 1 ]]; then + echo -en " ${nftname}\t ${rarity}" + tablecolumn=2 + else + echo -e "\t\t ${nftname}\t ${rarity}" + tablecolumn=1 + fi } +####### START + yn=n while [[ $yn == n ]]; do echo -en "\nPlease enter the moonrank collection ID: ${cyn}" @@ -109,13 +155,16 @@ echo -e "\nFound the ${bld}${name}${rst} collection of ${bld}${count}${rst} NFTs max=`echo ${count} | tr -d ,` [ $zeroindexed == "yes" ] && let max="max-1" || cur=1 +echo -e "\n" + didheader=0 thisseq=0 -echo -e "NFT ID\tRarity" +getrarity +tableheader while [[ $cur -le $max ]]; do getrarity + tablerow appendjson "${nftname}" ${rarity} - echo -e "${nftname}\t${rarity}" let cur="cur+1" let thisseq="thisseq+1" [ $thisseq -eq $sequential ] && thisseq=0 && sleep $delay @@ -123,8 +172,8 @@ done json="${json}}" -echo "$json" > ~/${collection}-rarity.json -echo -e "\nThe .json file for the ${name} NFT collection has been saved to ~/${collection}-rarity.json\n" +echo "$json" > ${directory}/${collection}-rarity.json +echo -e "\nThe .json file for the ${name} NFT collection has been saved to ${directory}/${collection}-rarity.json\n"