File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 44 "context" : [
55 {
66 "doi" : " https://schema.org/Time"
7- },
7+ }
88 ],
99 "fields" : [
1010 {
Original file line number Diff line number Diff line change 1+ """ Upload metadata definitions from a local directory of JSON definitions.
2+
3+ `python upload_definitions.py http://localhost:8000/api/v2 {API_KEY} definitions`
4+ """
5+
6+ import json
7+ import os
8+ import sys
9+
10+ import requests
11+
12+ if __name__ == "__main__" :
13+ # command line args
14+ args = sys .argv [1 :]
15+ # instance url
16+ api : str = args [
17+ 0
18+ ] # dev: http://localhost:8000/api/v2 prod: http://localhost/api/v2
19+ # api key
20+ token : str = args [1 ]
21+ # directory with json metadata definitions
22+ dir : str = args [2 ]
23+ # header for POST request
24+ headers = {"X-API-KEY" : token }
25+ # read definitions from local directory
26+ dir_list = os .listdir (dir )
27+ for file in dir_list :
28+ with open (os .path .join (dir , file )) as metadata_definition :
29+ json_definition = json .load (metadata_definition )
30+ response = requests .post (
31+ f"{ api } /metadata/definition" ,
32+ json = json_definition ,
33+ headers = headers ,
34+ )
35+ response .raise_for_status ()
36+ print (f"Uploaded { len (dir_list )} metadata definitions." )
You can’t perform that action at this time.
0 commit comments