-
Notifications
You must be signed in to change notification settings - Fork 4
/
pinByHash.py
46 lines (30 loc) · 1022 Bytes
/
pinByHash.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
import sys
import os
from os import path
from common.PinataKeyClass import PinataKey
sys.stdout.reconfigure(encoding='utf-8')
# construct the Pinata key object
keylist=PinataKey('pinataApiKey.csv')
endpoint = keylist.fetchEndpoint('pinByHash')
headers={}
hashToPin=''
pinataMetadata={'name':'','keyvalues':{}}
#pinByHash.py hash free/paid
# Parsing Parameter
if(len(sys.argv) != 4):
print("usage: python pinByHash.py hash name free/paid")
raise SystemExit
mode = sys.argv[3]
if (mode != 'free' and mode != 'paid'):
print("usage: either free or paid header")
raise SystemExit
hashToPin = sys.argv[1]
name = sys.argv[2]
mode = sys.argv[3]
print('hashToPin={}, name={}, mode={}'.format(hashToPin,name,mode))
headers=keylist.fetchKey(mode)
import requests
# Construct the json dict for the pinataMetadata. Only name will be processed
pinataMetadata['name']=name
resp = requests.post(endpoint, headers=headers, json={'hashToPin':hashToPin,'pinataMetadata':pinataMetadata})
print(str(resp))