-
Notifications
You must be signed in to change notification settings - Fork 12
/
nifty_gateway.py
62 lines (51 loc) · 1.88 KB
/
nifty_gateway.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import requests
import json
import os
from itertools import count
from utils import generate_blocklist, valid_hash
def list_nifty_gateway(update=True, verbose=False):
cache_fn = 'data/nifty-gateway-contracts.json'
cache = {}
if os.path.exists(cache_fn):
if verbose:
print('Loading Nifty Gateway contracts from cache...')
with open(cache_fn) as f:
cache = json.load(f)
if not update:
if verbose:
print('Returning Nifty Gateway contracts from cache...')
return cache
cache = {v:k for k,v in cache.items()} # swap key/value
blocklist = generate_blocklist()
if verbose:
print('Downloading from drops...')
for current_page in count(1):
url = f'https://api.niftygateway.com/drops/open/?size=100¤t={current_page}'
res = requests.get(url)
results = json.loads(res.content)['listOfDrops']
if len(results) == 0:
break
for drop in results:
for item in drop['Exhibitions']:
contract = item['contractAddress']
url = item['storeURL']
key = 'Nifty Gateway/' + url
if not valid_hash(contract, blocklist):
print('skipping', key, contract)
if contract in cache:
print('deleting old contract', contract)
del cache[contract]
continue
cache[contract] = key
if verbose:
print('Page', current_page, 'total', len(cache))
if verbose:
print('Done.')
if verbose:
print(f'Filtered: total {len(cache)}')
cache = {v:k for k,v in cache.items()} # swap key/value
with open(cache_fn, 'w') as f:
json.dump(cache, f, indent=2)
return cache
if __name__ == '__main__':
list_nifty_gateway(update=True, verbose=True)