|
2 | 2 | import requests |
3 | 3 | import secrets |
4 | 4 | import time |
| 5 | +import argparse |
| 6 | +from datetime import datetime |
| 7 | + |
| 8 | +parser = argparse.ArgumentParser() |
| 9 | +parser.add_argument('-f', '--file', help='the JSON file of records to post (including ".json"). optional - if not provided, the script will ask for input') |
| 10 | +parser.add_argument('-e', '--endpoint', help='the endpoint for the type of records being posted (e.g "resources" or "agents/people"). optional - if not provided, the script will ask for input') |
| 11 | +args = parser.parse_args() |
| 12 | + |
| 13 | +if args.file: |
| 14 | + file = args.file |
| 15 | +else: |
| 16 | + file = raw_input('Enter the JSON file of records to post (including ".json"): ') |
| 17 | +if args.endpoint: |
| 18 | + endpoint = args.endpoint |
| 19 | +else: |
| 20 | + endpoint = raw_input('Enter the endpoint for the type of records being posted (e.g "resources" or "agents/people"): ') |
5 | 21 |
|
6 | 22 | startTime = time.time() |
7 | 23 |
|
|
13 | 29 | session = auth["session"] |
14 | 30 | headers = {'X-ArchivesSpace-Session':session, 'Content_Type':'application/json'} |
15 | 31 |
|
16 | | -records = json.load(open('[JSON File].json')) |
| 32 | +f=csv.writer(open('postNew'+datetime.now().strftime('%Y-%m-%d %H.%M.%S')+'.csv', 'wb')) |
| 33 | +f.writerow(['post']) |
| 34 | + |
| 35 | +records = json.load(open(file)) |
17 | 36 | for i in range (0, len (records)): |
18 | 37 | record = json.dumps(records[i]) |
19 | | - post = requests.post(baseURL + '/agents/people', headers=headers, data=record).json() |
| 38 | + post = requests.post(baseURL + '/' + endpoint, headers=headers, data=record).json() |
| 39 | + post = json.dumps(post) |
20 | 40 | print post |
| 41 | + f.writerow([post]) |
21 | 42 |
|
22 | 43 | elapsedTime = time.time() - startTime |
23 | 44 | m, s = divmod(elapsedTime, 60) |
|
0 commit comments