k0rnh0li0 / rightclicker Goto Github PK
View Code? Open in Web Editor NEWAutomated right-clicking! Download whole NFT collections from OpenSea.
Automated right-clicking! Download whole NFT collections from OpenSea.
#!/usr/bin/env python3
import os
import sys
import signal
import requests
API_URL = "https://opensea.io/collection/boredapeyachtclub"
PAGE_SIZE = 50
QUIET = False
OUTPUT_DIR = "100"
usd_total = 100
def download_collection(boredapeyachtclub):
assets = None
page = 0
#\TODO create collection directory
while True:
if page * PAGE_SIZE > 10000:
# API restriction - can only use offsets up to 10000
break
req_url = API_URL + "/assets"
req_params = {
"collection": boredapeyachtclub,
"offset": page * PAGE_SIZE,
"limit": PAGE_SIZE,
"order_direction": "asc"
}
# Get assets in collection
resp = requests.get(req_url, params=req_params)
if resp.status_code != 200:
print(f"Error {resp.status_code} on page {page} of collection '{boredapeyachtclub}'")
break
# Convert API response to JSON
try:
resp = resp.json()
except Exception as e:
print(e)
break
assets = resp["assets"]
if assets == []:
if page == 0:
print(f"Collection '{boredapeyachtclub}' does not exist")
break
# Verify that the output directory exists
if not os.path.isdir(OUTPUT_DIR + "/" + boredapeyachtclub):
os.mkdir(OUTPUT_DIR + "/" + boredapeyachtclub)
# Download all assets on this page
for asset in assets:
download_asset(boredapeyachtclub, asset)
page += 1
def download_asset(collection, asset):
global usd_total
# Name of this asset
asset_name = asset["name"]
if asset_name is None:
asset_name = asset["token_id"]
# URL of asset content
asset_url = ""
if asset["animation_url"] is not None:
asset_url = asset["animation_url"]
elif asset["image_url"] is not None:
asset_url = asset["image_url"]
if asset_url == "":
return
# USD value of the asset
# Will be zero if no one was dumb enough to buy it yet
last_price = 0
if asset["last_sale"] is not None:
token_price_usd = float(asset["last_sale"]["payment_token"]["usd_price"])
token_decimals = asset["last_sale"]["payment_token"]["decimals"]
total_price = int(asset["last_sale"]["total_price"]) / 10**(token_decimals)
last_price = int(total_price * token_price_usd)
# Download asset content
req = requests.get(asset_url, stream=True)
# Output file extension
asset_ext = ""
ctype = req.headers["Content-Type"]
if "image" in ctype or "video" or "audio" in ctype:
asset_ext = ctype.split("/")[1]
else:
print(f"Unrecognized Content-Type: {ctype}")
asset_ext = "bin"
# Output file path
output_file = f"{OUTPUT_DIR}/{collection}/{asset_name}.{asset_ext}"
if os.path.exists(output_file):
# File already exists - don't re-download it
return
with open(output_file, "wb") as f:
for chunk in req.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
if not QUIET:
print(f"{asset_name} - ${last_price}")
usd_total += last_price
def parse_flag(flag):
flag = flag.split("=")
prop = flag[0].lower()
if prop == "quiet":
global QUIET
QUIET = True
elif prop == "output-dir":
global OUTPUT_DIR
OUTPUT_DIR = flag[1]
else:
print(f"Unrecognized flag '{prop}'")
exit()
def finish():
print(f"\nYou acquired ${usd_total} worth of NFTs!\n")
exit()
def sig_handler(num, frame):
finish()
if name == "main":
print("nft-rightclicker")
print("All your NFTs are mine now!")
print("k0rnh0li0 2021")
print("https://twitter.com/gr8_k0rnh0li0\n")
if len(sys.argv) < 2:
print("At least one NFT collection must be specified.")
exit()
# First handle flags
for v in sys.argv[1:]:
if v[0:2] == "--":
parse_flag(v[2:])
# Create root NFT collections directory if necessary
if not os.path.isdir(OUTPUT_DIR):
os.mkdir(OUTPUT_DIR)
# Set handler for CTRL+C
signal.signal(signal.SIGINT, sig_handler)
# Download all specified NFT collections
for v in sys.argv[1:]:
if v[0:2] == "--":
continue
download_collection(v)
finish()
After i copy pasted the python3 rightclick.py boredapeyachtclub it says that Python is not found. What should i do?
Is there a way to specify traits, like if I wanted to only download gold traited ones? or just ones with a certain body type?
trying to download a collection but it says that it doesn't exist, how i can fix this?
GTA 6 heists be like:
please clear guide me how i do this code,you are wrote right but i am not a profitional please guide how i run this script
#!/usr/bin/env python3
import os
import sys
import signal
import requests
API_URL = "https://api.opensea.io/collection/boredapeyachtclub"
PAGE_SIZE = 50
QUIET = False
OUTPUT_DIR = "100"
usd_total = 0
def download_collection(boredapeyachtclub):
assets = None
page = 0
#\TODO create collection directory
while True:
if page * PAGE_SIZE > 10000:
# API restriction - can only use offsets up to 10000
break
req_url = API_URL + "/assets"
req_params = {
"collection": boredapeyachtclub,
"offset": page * PAGE_SIZE,
"limit": PAGE_SIZE,
"order_direction": "asc"
}
# Get assets in collection
resp = requests.get(req_url, params=req_params)
if resp.status_code != 200:
print(f"Error {resp.status_code} on page {page} of collection '{boredapeyachtclub}'")
break
# Convert API response to JSON
try:
resp = resp.json()
except Exception as e:
print(e)
break
assets = resp["assets"]
if assets == []:
if page == 0:
print(f"Collection '{boredapeyachtclub}' does not exist")
break
# Verify that the output directory exists
if not os.path.isdir(OUTPUT_DIR + "/" + boredapeyachtclub):
os.mkdir(OUTPUT_DIR + "/" + boredapeyachtclub)
# Download all assets on this page
for asset in assets:
download_asset(boredapeyachtclubs, asset)
page += 1
def download_asset(collection, asset):
global usd_total
# Name of this asset
asset_name = asset["name"]
if asset_name is None:
asset_name = asset["token_id"]
# URL of asset content
asset_url = ""
if asset["animation_url"] is not None:
asset_url = asset["animation_url"]
elif asset["image_url"] is not None:
asset_url = asset["image_url"]
if asset_url == "":
return
# USD value of the asset
# Will be zero if no one was dumb enough to buy it yet
last_price = 0
if asset["last_sale"] is not None:
token_price_usd = float(asset["last_sale"]["payment_token"]["usd_price"])
token_decimals = asset["last_sale"]["payment_token"]["decimals"]
total_price = int(asset["last_sale"]["total_price"]) / 10**(token_decimals)
last_price = int(total_price * token_price_usd)
# Download asset content
req = requests.get(asset_url, stream=True)
# Output file extension
asset_ext = ""
ctype = req.headers["Content-Type"]
if "image" in ctype or "video" or "audio" in ctype:
asset_ext = ctype.split("/")[1]
else:
print(f"Unrecognized Content-Type: {ctype}")
asset_ext = "bin"
# Output file path
output_file = f"{OUTPUT_DIR}/{collection}/{asset_name}.{asset_ext}"
if os.path.exists(output_file):
# File already exists - don't re-download it
return
with open(output_file, "wb") as f:
for chunk in req.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
if not QUIET:
print(f"{asset_name} - ${last_price}")
usd_total += last_price
def parse_flag(flag):
flag = flag.split("=")
prop = flag[0].lower()
if prop == "quiet":
global QUIET
QUIET = True
elif prop == "output-dir":
global OUTPUT_DIR
OUTPUT_DIR = flag[1]
else:
print(f"Unrecognized flag '{prop}'")
exit()
def finish():
print(f"\nYou acquired ${usd_total} worth of NFTs!\n")
exit()
def sig_handler(num, frame):
finish()
if name == "main":
print("nft-rightclicker")
print("All your NFTs are mine now!")
print("k0rnh0li0 2021")
print("https://twitter.com/gr8_k0rnh0li0\n")
if len(sys.argv) < 2:
print("At least one NFT collection must be specified.")
exit()
# First handle flags
for v in sys.argv[1:]:
if v[0:2] == "--":
parse_flag(v[2:])
# Create root NFT collections directory if necessary
if not os.path.isdir(OUTPUT_DIR):
os.mkdir(OUTPUT_DIR)
# Set handler for CTRL+C
signal.signal(signal.SIGINT, sig_handler)
# Download all specified NFT collections
for v in sys.argv[1:]:
if v[0:2] == "--":
continue
download_collection(v)
finish()
If the user has an API key, it would be very useful to add to the speed and stability of this by adding in an optional variable, like:
Python3 rightclick.py cool-cats-nft --apikey thisismyAPIkey
I'm struggling with a way to make OpenSea's API report back the value of the unsold NFTs- could this be added into this rightclicker, instead of unsold NFTs having a value of 0?
how to run script
Not working for me. Breaking changes to the API maybe?
I tried on different devices and each time downloads just 1.007 and then suddenly stops and say something about line 180, but doesn't say error, what can I do to fix that and to download the 10.000?
the image file type comes as svg + xml, is there any way to cnvert it to png. Online converters work but for 3333,4444 collection nfts.....hectic work
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.