Git Product home page Git Product logo

rightclicker's People

Contributors

k0rnh0li0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rightclicker's Issues

how to run this script

#!/usr/bin/env python3

rightclick.py

Automatically acquire whole NFT collections from OpenSea.

k0rnh0li0 2021

import os
import sys
import signal
import requests

Constants

Root OpenSea API URL

API_URL = "https://opensea.io/collection/boredapeyachtclub"

Number of assets per page

PAGE_SIZE = 50

Configuration

If True, do not print info about individual assets

QUIET = False

Directory to save downloaded collections to

OUTPUT_DIR = "100"

Total value of all downloaded NFTs

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()

Python was not found

After i copy pasted the python3 rightclick.py boredapeyachtclub it says that Python is not found. What should i do?

Feature Request

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?

Can't find collection

trying to download a collection but it says that it doesn't exist, how i can fix this?

lol

GTA 6 heists be like:

i am not understanding

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

why he said At least one NFT collection must be specified.

#!/usr/bin/env python3

rightclick.py

Automatically acquire whole NFT collections from OpenSea.

k0rnh0li0 2021

import os
import sys
import signal
import requests

Constants

Root OpenSea API URL

API_URL = "https://api.opensea.io/collection/boredapeyachtclub"

Number of assets per page

PAGE_SIZE = 50

Configuration

If True, do not print info about individual assets

QUIET = False

Directory to save downloaded collections to

OUTPUT_DIR = "100"

Total value of all downloaded NFTs

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()

Feature Request: Integrate API Key

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

Use value of unsold NFTs?

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?

Broken

Not working for me. Breaking changes to the API maybe?

Downloads 1.007 and then stops

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?

image file type

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.