Skip to content

Commit

Permalink
Merge pull request #15 from mjanowiecki/master
Browse files Browse the repository at this point in the history
add new script and update readme
  • Loading branch information
ehanson8 authored Dec 13, 2018
2 parents 1b0878c + b3e3901 commit 0933681
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ Creates instances (consisting of top_containers) from a separate CSV file. The C
#### [postContainerLinksToRecords.py](/postContainerLinksToRecords.py)
Based on user input, posts containers to a specified record based on a specified CSV file.

#### [postContainerLinksToRecordsFromCSV.py](/postContainerLinksToRecordsFromCSV.py)
Based on user input, posts containers to a specified record based on a specified CSV file of top container and resource URIs.

#### [postCorporateAgentsFromCSV.py](/postCorporateAgentsFromCSV.py)
Based on user input, posts corporate agents based on a specified CSV file.

Expand Down
50 changes: 50 additions & 0 deletions postContainerLinksToRecordsFromCSV.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import json
import requests
import secrets
import csv

secretsVersion = raw_input('To edit production server, enter the name of the secrets file: ')
if secretsVersion != '':
try:
secrets = __import__(secretsVersion)
print 'Editing Production'
except ImportError:
print 'Editing Development'
else:
print 'Editing Development'

targetFile = raw_input('Enter file name: ')

baseURL = secrets.baseURL
user = secrets.user
password = secrets.password
repository = secrets.repository

auth = requests.post(baseURL + '/users/'+user+'/login?password='+password).json()
session = auth["session"]
headers = {'X-ArchivesSpace-Session':session, 'Content_Type':'application/json'}

csvfile = csv.DictReader(open(targetFile))

f=csv.writer(open('containerLinksPostedFromCSV.csv', 'wb'))
f.writerow(['topContainer']+['resource']+['post'])

for row in csvfile:
uri = row['uri']
resourceUri = row['resourceuri']
print baseURL+resourceUri
asRecord = requests.get(baseURL+resourceUri, headers=headers).json()
instanceArray = asRecord['instances']
top_container = {}
top_container['ref'] = uri
sub_container = {}
sub_container['top_container'] = top_container
instance = {}
instance['sub_container'] = sub_container
instance['instance_type'] = 'mixed_materials'
instanceArray.append(instance)
asRecord['instances'] = instanceArray
asRecord = json.dumps(asRecord)
post = requests.post(baseURL+resourceUri, headers=headers, data=asRecord).json()
print post
f.writerow([uri]+[resourceUri]+[post])

0 comments on commit 0933681

Please sign in to comment.