-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnft_stealer_cli_version.py
65 lines (56 loc) · 2.61 KB
/
nft_stealer_cli_version.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
63
64
65
import os
import math
import json
import requests
from argparse import ArgumentParser
def run_nft_stealer(collection, image, quality, data):
if not image and not data:
print(f"Terminating program as both images and data arguments are set to False.")
exit()
header = {'User-Agent': 'Mozilla/5.0 (X11; Arch; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1'}
collection_data = requests.get(f"https://api.opensea.io/api/v1/collection/{collection}?format=json", headers=header)
count = int(json.loads(collection_data.content.decode())["collection"]["stats"]["count"])
if not collection_data.status_code == 200:
collection_data.raise_for_status()
exit()
if not os.path.exists(f'./images'):
os.mkdir(f'./images')
if not os.path.exists(f'./images/{collection}'):
os.mkdir(f'./images/{collection}')
if not os.path.exists(f'./images/{collection}/data') and data:
os.mkdir(f'./images/{collection}/data')
for i in range(math.ceil(count / 50)):
data_request = json.loads(requests.get(
f"https://api.opensea.io/api/v1/assets?order_direction=asc&offset={i * 50}"
f"&limit=50&collection={collection}&format=json", headers=header).content.decode())
if image:
for asset in data_request["assets"]:
formatted_number = asset['token_id']
if not os.path.exists(f"./images/{collection}/{formatted_number}.png"):
if quality and asset["image_original_url"]:
image_file = requests.get(asset["image_original_url"])
else:
if asset["image_url"]:
image_file = requests.get(asset["image_url"])
else:
continue
if image_file.status_code == 200:
file = open(f"./images/{collection}/{formatted_number}.png", "wb+")
file.write(image_file.content)
file.close()
if data:
for asset in data_request["assets"]:
formatted_number = f"{int(asset['token_id']):04d}"
if not os.path.exists(f"./images/{collection}/data/{formatted_number}.json"):
file = open(f"./images/{collection}/data/{formatted_number}.json", "w+")
json.dump(asset, file, indent=3)
file.close()
print("Collection files downloaded.")
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument("-c", "--collection", required=True, help="The collection tag", dest="collection")
parser.add_argument("-i", "--images", action='store_true', help="Download images", dest="images")
parser.add_argument("-q", "--quality", action='store_true', help="Prefer high quality", dest="quality")
parser.add_argument("-d", "--data", action='store_true', help="Download JSON data", dest="data")
parser = parser.parse_args()
run_nft_stealer(parser.collection, parser.images, parser.quality, parser.data)