Skip to content

Commit

Permalink
Merge pull request #4 from PABourdais/add-duration
Browse files Browse the repository at this point in the history
Add duration (days) of holding
  • Loading branch information
PABourdais committed Nov 21, 2022
2 parents bca3fab + 3e5d465 commit c982d16
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 5 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ Check your Python version by running:
$ python3 --version
```

Check if pip is installed, otherwise install it:

```shell
$ pip help
```

After that run

```shell
Expand All @@ -23,14 +29,30 @@ $ pip install -r requirements.txt

##### 2. Run the script

#### Simple case:

```bash
python get-nfts-list.py --ticker EBUDDIES-e18a04
```

#### Get the NFTs for a specific trait/attribute:

```bash
python get-nfts-list.py --ticker EBUDDIES-e18a04 --trait_type Mouth --name Smile
```

#### Get the NFTs for a number of day(s) of holding:

```bash
python get-nfts-list.py --ticker EBUDDIES-e18a04 --duration 2
```

#### Get the NFTs for a specific trait/attribute and for a number of day(s) of holding:

```bash
python get-nfts-list.py --ticker EBUDDIES-e18a04 --trait_type Mouth --name Smile --duration 2
```

Check the **output** folder for results.


Expand Down
63 changes: 58 additions & 5 deletions get-nfts-list.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import time
import sys

from datetime import datetime
from datetime import datetime, timedelta
from pathlib import Path

# Inputs
parser = argparse.ArgumentParser()
parser.add_argument("--ticker", help="Ticker of the collection", required=True)
parser.add_argument("--trait_type", help="Item to retrieve", required=False)
parser.add_argument("--name", help="Item to retrieve", required=False)
parser.add_argument("--duration", help="Number of day(s) of holding", required=False)

args = parser.parse_args()

Expand All @@ -32,11 +33,17 @@
ISENGARD_WALLET_ADDRESS]

nft_collection_name = args.ticker
days_of_holding = 0 if args.duration is None else int(args.duration)
values = []
single_wallet = []
all_wallet = []
current_date = datetime.now()

if days_of_holding > 0:
end_date = current_date + timedelta(days=-days_of_holding)
timestamp = end_date.timestamp()
timestamp = int(timestamp)

i = 0
while i < 10000:
nfts = requests.get(f'https://api.elrond.com/collections/{nft_collection_name}/nfts?from=' + str(
Expand Down Expand Up @@ -72,13 +79,57 @@
txt_file = current_date.strftime(f"%b-%d-%Y-{nft_collection_name}-{args.name}.txt")
result_csv = current_date.strftime(f"output/%b-%d-%Y-{nft_collection_name}-{args.name}")
else:
txt_file = current_date.strftime(f"%b-%d-%Y-{nft_collection_name}.txt")
result_csv = current_date.strftime(f"output/%b-%d-%Y-{nft_collection_name}")
if args.duration is not None and days_of_holding > 0:
txt_file = current_date.strftime(f"%b-%d-%Y-with-duration-{nft_collection_name}.txt")
result_csv = current_date.strftime(f"output/%b-%d-%Y-with-duration-{nft_collection_name}")
else:
txt_file = current_date.strftime(f"%b-%d-%Y-{nft_collection_name}.txt")
result_csv = current_date.strftime(f"output/%b-%d-%Y-{nft_collection_name}")

for wallet in single_wallet:
if wallet not in black_listed_addresses:
value = {"owner": wallet, "nftsCount": all_wallet.count(wallet)}
values.append(value)
if args.duration is None or days_of_holding == 0:
value = {"owner": wallet, "nftsCount": all_wallet.count(wallet)}
values.append(value)
elif args.duration is not None and days_of_holding > 0:
api_url = f"https://api.elrond.com/accounts/{wallet}/nfts?size=10000&search={nft_collection_name}"
r = requests.get(api_url)
nfts = r.json()
all_nfts = len(nfts)
if args.trait_type and args.name:
eligible_nfts = 0
for nft in nfts:
time.sleep(0.09)
nft_identifier = nft["identifier"]
try:
for item_query in nft['metadata']['attributes']:
if args.trait_type == item_query['trait_type'] and args.name == item_query['value']:
transactions_with_nfts_url = f"https://api.elrond.com/transactions?status=success&token={nft_identifier}&after={timestamp}&withScamInfo=false"
r = requests.get(transactions_with_nfts_url)
txs = r.json()
if len(txs) == 0:
# didn't found transactions, adding to eligible nfts
eligible_nfts = eligible_nfts + 1
except:
pass

value = {"owner": wallet, "nftsCount": eligible_nfts}
values.append(value)
else:
eligible_nfts = all_nfts
for nft in nfts:
time.sleep(0.09)
nft_identifier = nft["identifier"]
eligible_nfts = all_nfts
transactions_with_nfts_url = f"https://api.elrond.com/transactions?status=success&token={nft_identifier}&after={timestamp}&withScamInfo=false"
r = requests.get(transactions_with_nfts_url)
txs = r.json()
if len(txs) != 0:
# found transactions, subtracting from eligible nfts
eligible_nfts = eligible_nfts - 1

value = {"owner": wallet, "nftsCount": eligible_nfts}
values.append(value)

# Create output
name_of_file = "output/{}".format(txt_file)
Expand All @@ -92,6 +143,7 @@
with open(current_date.strftime(f"{result_csv}.csv"), "wt") as fp:
writer = csv.writer(fp, delimiter=",")
writer.writerow(["Address", "Count"]) # write header

for output in values:
func_txt.write(output.__str__() + "\n")
writer.writerow([output['owner'], output['nftsCount']])
Expand All @@ -111,4 +163,5 @@
print(f'Number of wallets: {len(values)}')
print(f'Number of NFTs: {total_nft}\n')
print(f'Average Nbr of NFTs per wallet {average}\n')
print('No duration specified' if args.duration is None else f'For last {days_of_holding} Day(s)')
print(f'\n----- Made by ElrondBuddies <3 -----\n')

0 comments on commit c982d16

Please sign in to comment.