0%

galaxy | 通过 python 获取 galaxy 中的 NFT

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

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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("地址")
请我喝杯咖啡吧~