1

galaxy | 通过 python 获取 galaxy 中的 NFT

 2 years ago
source link: https://benpaodewoniu.github.io/2022/05/06/galaxy2/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

galaxy | 通过 python 获取 galaxy 中的 NFT

发表于

2022-05-06 分类于 区块链dappgalaxy

阅读次数: 8 Valine: 0

这里主要指通过调用接口的方式来获取 galaxy 中某一 address 下面的所有 NFT。

这里直接上代码,另外,关于如何找到该接口的方式,请参考。

这里不多啰嗦,直接上代码。

import json
import time

import requests

Headers = {
"accept": "*/*",
"content-type": "application/json",
"authorization": "null",
"sec-ch-ua-mobile": "?0",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36",
"sec-ch-ua-platform": "macOS",
"Sec-Fetch-Site": "same-site",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Dest": "empty"
}


def get_nfts(address):
try:
print(f"地址 {address} 获得 NFT 的情况如下")
data1 = """{"operationName":"MyNFTs","variables":{"address":""" + '"' + address + '"' + ""","option":{"orderBy":"CreateTime","order":"DESC","first":1000}},"query":"query MyNFTs($address: String!, $option: ListNFTInput!) { addressInfo(address: $address) { id nfts(option: $option) { totalCount pageInfo { endCursor __typename } list { id name campaign { id gamification { id type __typename } dao { id name logo alias isVerified __typename } __typename } image powah category treasureBack animationURL nftCore { id name symbol contractAddress spaceStationAddress dao { id name logo alias isVerified __typename } __typename } __typename } __typename } __typename }}"}"""

response = requests.post("https://graphigo.prd.galaxy.eco/query", data=data1, headers=Headers)
if response.status_code != 200:
print(f"\t 获取信息出错")
else:
if (len(json.loads(response.text).get("data").get("addressInfo").get("nfts").get("list")) == 0):
time.sleep(5)
else:
for info in json.loads(response.text).get("data").get("addressInfo").get("nfts").get("list"):
try:
print(
f"\t name: {info.get('nftCore').get('name')} symbol: {info.get('nftCore').get('symbol')} contract: {info.get('nftCore').get('contractAddress')} category: {info.get('category')} id:{info.get('id')}")
except Exception as e:
print("\t 数据解析错误")

except Exception as e:
print(f"\t 获取信息出错")


if __name__ == '__main__':
# 将下面的 地址进行替换就可以了
# 环境 python3.6
get_nfts("地址")
请我喝杯咖啡吧~

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK