[英]Trying to print all owners of an NFT collection on OpenSea using API and Python 3
I am trying to get a list of owners of the collection Aethir Wars on Opensea.io.我想在 Opensea.io 上获取 Aethir Wars 收藏的所有者列表。 I want the owner, which NFT they hold, and their ETH address.我想要所有者,他们持有的 NFT,以及他们的 ETH 地址。 I am able to get a long list of owners and their address, but the list isn't complete for some reason.我可以获得一长串所有者及其地址,但由于某种原因,该列表并不完整。 Also, I had to add an if statement because if an NFT was transferred and not purchased, the "Last_Sale" Parameter is null.另外,我必须添加一个 if 语句,因为如果 NFT 被转移而不是购买,则“Last_Sale”参数为空。 Any help is appreciated.任何帮助表示赞赏。
import requests
url = "https://api.opensea.io/api/v1/assets"
api_key = "api key"
col = 'reapers'
def print_owners(race, offset):
querystring = {'order_by': 'name', 'order_direction': 'asc', 'offset': offset, 'limit': '50',
'collection': col, 'X-API-KEY': api_key}
response = requests.get(url, params=querystring)
data = response.json()
i = 0
for each_asset in data['assets']:
try:
if race in data['assets'][0]['name']:
if data["assets"][i]["last_sale"] is None:
print(data["assets"][i]["name"] + ': '
+ data["assets"][i]["sell_orders"][0]["maker"]["address"])
else:
print(data["assets"][i]["name"] + ': '
+ data["assets"][i]["last_sale"]["transaction"]["from_account"]["user"]["username"])
except TypeError:
pass
i += 1
x = range(0, 600, 50)
for stuff in x:
try:
print_owners(race='Reaper', offset=str(stuff))
except KeyError:
pass
try:
print_owners(race='Android', offset=str(stuff))
except KeyError:
pass
try:
print_owners(race='Goblin', offset=str(stuff))
except KeyError:
pass
I have found a lot of examples where any of these ["user"]["username"]['name'] are Null.我发现了很多例子,其中任何 ["user"]["username"]['name'] 都是 Null。 If you don't handle the If == Null it throws an exception.如果您不处理 If == Null,则会引发异常。
I have a sample that appears to work in Python, using streamlit.我有一个使用 streamlit 似乎可以在 Python 中工作的示例。
Regards,问候,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.