Scripts for automating OpenSea operations
Project description
OpenSeaScripts
A suite of Python scripts for using OpenSea where API's are limited. OSS uses Selenium to control a Google Chrome window to find, fetch, and interact with HTML elements on OpenSea's website.
Application
This Python module is intended for uploading and listing for sale many NFT's to OpenSea. Their API does not support uploading, and to avoid manually uploading collections of potentially hundreds of NFT's, this module can be used. I used this to upload my collection of Monkey Men.
This module supports all asset options on OpenSea using the AssetOptions class. Properties, levels, and stats will all be added to your NFT and displayed on the page just like any other NFT.
Installation
pip install OpenSeaScripts
You will also need Google Chrome.
Usage
from OpenSeaScripts.AssetOptions import AssetOptions
from OpenSeaScripts.OSSBrowser import OSSBrowser
import datetime
# Create a new browser. This will open a Chrome window.
browser = OSSBrowser()
# Use the information displayed here to avoid signing in to MetaMask
# each time the program is run:
print("Browser info:", browser.get_session_data())
# Create a new asset object with the file NFT.png, titled "NFT"
my_asset = AssetOptions("NFT.png", "NFT")
my_asset.set_description("An NFT.")
my_asset.set_external_link("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
# Add attributes to your NFT
my_asset.add_property("Type", "Image")
my_asset.add_property("Color", "Blue")
my_asset.add_level("Number", "1", "4")
my_asset.add_stat("Size", "50", "100")
# Set the asset to upload on the Polygon blockchain
my_asset.set_blockchain("Polygon") # "Ethereum" also works
# You will need to install the MetaMask extension in the browser
# and connect your wallet to OpenSea before uploading assets.
input("Please sign in to OpenSea using MetaMask. Press Enter when ready... ")
# Perform the uploading process in the browser window
result = browser.upload_asset(my_asset)
# "result" will be False if the upload failed, or the OpenSea URL of the NFT if successful.
if not result:
print("Upload failed.")
else:
print("Uploaded asset. URL:", result)
sell_start = datetime.datetime(2022, 1, 13, 0, 0) # Sell duration start datetime object.
sell_end = datetime.datetime(2022, 4, 13, 0, 0) # Sell duration end datetime object.
# The sell_start must be in the future but within 30 days.
# The sell_end must be past sell_start, but no more than 6 months later.
sell_result = browser.sell_asset(result, 1, sell_start, sell_end) # List the NFT for sale using its URL for the price of 1 ETH, and with the start and end sell times above
if not result:
print("Sell failed.")
else:
print("Asset listed for sale.")
Easily Reconnect to Existing Browser Session
Selenium allows you to connect to a previously opened browser session. You can use this to avoid having to sign in to MetaMask each time you run a script to upload NFT's. However, certain things must be done to ensure that the first session stays open.
I recommend doing this with two different Python scripts. The first will initailize the browser, print the connection info, and then keep the session open. The second will actually connect to the browser and can be restarted without closing the browser session.
StartBrowser.py
from OpenSeaScripts.OSSBrowser import OSSBrowser
browser = OSSBrowser()
print("Browser info:", browser.get_session_data()) # Use this info to reconnect
# Keep the browser open for reconnecting
while True:
pass
ConnectToBrowser.py
from OpenSeaScripts.OSSBrowser import OSSBrowser
# Browser info from StartBrowser.py
command_executor_url = ""
session_id = ""
browser = OSSBrowser(command_executor_url, session_id)
# Upload / Sell Assets
:warning: I have noticed some issues with opening and then reconnecting to a browser in the Visual Studio Code console. I recommend you run scripts that open browser windows in a different terminal winodw.
Future Features
- Better error messages
- Documentation
- Example programs
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for OpenSeaScripts-1.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38cb433d0200f053b8b6e14868b1183370f08dd1e17e67b6e1247c9de0a5f99f |
|
MD5 | adfc6e41e45e96286d5d5b147a5efaed |
|
BLAKE2b-256 | 965a24d80ce7398811605e68efcdb5d840b46ffd26d7e72504224eeb1b5d7d69 |