简体   繁体   English

尝试使用 API 和 Python 3 在 OpenSea 上打印 NFT 集合的所有所有者

[英]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.

相关问题 有什么方法可以使用合约地址获取 NFT(在 OpenSea 等市场上列出)的销售状态? - Is there any way to get the sale status of an NFT (listed on marketplaces like OpenSea) using their contract address? 如何使用 python 在 opensea 中列出或出售物品 - How list or sell item in opensea using python 尝试使用Python打印JSON数据 - Trying to print JSON data using Python 使用Python的Facebook API。 如何打印所有帖子的评论? - Facebook API using Python. How to print out comments from ALL post? Raspberry Pi和Python 2.7-尝试打印给所有用户 - Raspberry Pi & Python 2.7 - trying to print to all users Python - 尝试以某种方式从 API 结果打印 json 数据 - Python - Trying to print json data from API results in a certain way 无法使用 Python 打印产品的所有标题 - Unable to print all title of product using Python 无法通过Python使用Overpass API打印查询 - Failing to print query using Overpass API with Python 我怎样才能做到这一点? 我正在尝试使用 python 按顺序打印所有数字的输入 - how can i achieve this ? I'm trying to have an Input that will print out all the numbers in sequential order using python 尝试在python中打印exec - Trying to print exec in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM