-
Notifications
You must be signed in to change notification settings - Fork 4
/
pin_tokens.py
74 lines (60 loc) · 2.07 KB
/
pin_tokens.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import json, requests, sys, getopt
from ipfs_utils import IPFSPinner
def do_fxhash_request(id, take, skip):
url = "https://api.fxhash.xyz/graphql/"
query = f"""{{
generativeToken(id: {id}){{
name
metadataUri
metadata
objkts(take: {take}, skip: {skip}) {{
name
metadataUri
metadata
}}
}}
}}"""
return requests.post(url, json={'query': query})
def main(argv):
GT_id = ''
api_key = ''
api_secret = ''
service_type = 'infura'
try:
opts, args = getopt.getopt(argv, "i:k:s:t:",["id=","api_key=","api_secret=","service_type="])
except:
print("Error in arguments: pin_tokens.py --id <GT_token> --api_key <api_key> --api_secret <api_secret> --service_type [pinata|ipfs|infura]")
for opt, arg in opts:
if opt in ['-i', '--id']:
GT_id = arg
elif opt in ['-k', '--api_key']:
api_key = arg
elif opt in ['-s', '--api_secret']:
api_secret = arg
elif opt in ['-t', '--service_type']:
service_type = arg
pinner = IPFSPinner(service_type, api_key, api_secret)
valid_request = True
token_count = 0
take_count = 20
while valid_request:
# Do multiple requests to get all tokens, like a pagination.
r = do_fxhash_request(GT_id, take_count, token_count)
token_count += take_count
if r.status_code == 200:
binary = r.content
output = json.loads(binary)
output = output['data']['generativeToken']
# Pinning the objkts generated from the generative token
for objkt in output['objkts']:
pinner.pinToken(objkt)
print("\n")
if len(output['objkts']) < take_count:
# Pinning the generative token metadata & example
pinner.pinToken(output)
print("\n")
break
else:
print(f'Error {str(r.status_code)}')
valid_request = False
main(sys.argv[1:])