-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpin_creations.py
58 lines (45 loc) · 1.75 KB
/
pin_creations.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
import json, requests, sys, getopt
from ipfs_utils import IPFSPinner
def do_fxhash_request(wallet, take, skip):
url = "https://api.fxhash.xyz/graphql/"
query = f'{{user(id: "{wallet}") {{generativeTokens(take: {take}, skip: {skip}) {{name metadataUri metadata}}}}}}'
return requests.post(url, json={'query': query})
def main(argv):
wallet = ''
api_key = ''
api_secret = ''
service_type = 'infura'
try:
opts, args = getopt.getopt(argv, "w:k:s:t:",["wallet=","api_key=","api_secret=","service_type="])
except:
print("Error in arguments: pin_creations.py --wallet <wallet> --api_key <api_key> --api_secret <api_secret> --service_type [pinata|ipfs|infura]")
for opt, arg in opts:
if opt in ['-w', '--wallet']:
wallet = 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(wallet, take_count, token_count)
token_count += take_count
if r.status_code == 200:
binary = r.content
output = json.loads(binary)
output = output['data']['user']['generativeTokens']
for objkt in output:
pinner.pinToken(objkt)
print("\n")
if len(output) < take_count:
break
else:
print(f'Error {str(r.status_code)}')
valid_request = False
main(sys.argv[1:])