Пример #1
0
def delete_do_instance():
    values = admin.login()
    csvfile = admin.opencsv()
    txtfile = admin.opentxt()
    for row in csvfile:
        archival_object_uri = row[0]
        digital_object_uri = row[1] #may or may not need this...could just loop through instances and check for DOs, then delete
        #OR could find a specific digital object instance I want to delete
        try:
            archival_object_json = requests.get(values[0] + archival_object_uri, headers=values[1]).json()
            instance_list = list(archival_object_json['instances'])
            if digital_object_uri == '':
                for instance in instance_list:
                    if instance['instance_type'] == 'digital_object':
                        archival_object_json['instances'].remove(instance)
                archival_object_data = json.dumps(archival_object_json)
                archival_object_update = requests.post(values[0] + archival_object_uri, headers=values[1], data=archival_object_data).json()
                admin.writetxt(txtfile, archival_object_update)
                print(archival_object_update)
            else:
                for instance in instance_list:
                    if 'digital_object' in instance:
                        if instance['digital_object'] == {'ref': digital_object_uri}:
                            archival_object_json['instances'].remove(instance)
                archival_object_data = json.dumps(archival_object_json)
                archival_object_update = requests.post(values[0] + archival_object_uri, headers=values[1], data=archival_object_data).json()
                admin.writetxt(txtfile, archival_object_update)
                print(archival_object_update)
        except:
            txtfile.write('error, could not update ' + str(archival_object_uri))
            continue
Пример #2
0
def delete_records():
    values = admin.login()
    csvfile = admin.opencsv()
    txtfile = admin.opentxt()
    for row in csvfile:
        record_uri = row[0]
        try:
            record_json = requests.get(values[0] + record_uri, headers=values[1]).json()
            record_data = json.dumps(record_json)
            delete = requests.delete(values[0] + record_uri, headers=values[1], data=record_data).json()
            admin.writetxt(txtfile, delete)
            print(delete)
        except:
            txtfile.write('error, could not delete ' + str(record_uri))
            continue
Пример #3
0
def create_singlepart_notes():
    values = admin.login()
    csvfile = admin.opencsv()
    txtfile = admin.opentxt()
    for row in csvfile:
        record_uri = row[0]
        note_text = row[1]
        note_type = row[2]
        record_json = requests.get(values[0] + record_uri, headers=values[1]).json()
        new_note = {'jsonmodel_type': 'note_singlepart', 'content': [note_text],
                    'type': note_type}
        record_json['notes'].append(new_note)
        record_data = json.dumps(record_json)
        record_update = requests.post(values[0] + record_uri, headers=values[1], data=record_data).json()
        admin.writetxt(txtfile, record_update)
        print(record_update)
Пример #4
0
def delete_notes():
    values = admin.login()
    csvfile = admin.opencsv()
    txtfile = admin.opentxt()
    for row in csvfile:
        resource_uri = row[0]
        persistent_id = row[1]
        resource_json = requests.get(values[0] + resource_uri, headers=values[1]).json()
        for key, valuelist in resource_json.items():
            if key == 'notes':
                for note in valuelist:
                    newdict = {k:v for k,v in note.items()}
                    for key, value in newdict.items():
                        if value == persistent_id:
                            note.clear()
        resource_data = json.dumps(resource_json)
        resource_update = requests.post(values[0] + resource_uri, headers=values[1], data=resource_data).json()
        admin.writetxt(txtfile, resource_update)
        print(resource_update)
Пример #5
0
def create_multipart_notes():
    values = admin.login()
    csvfile = admin.opencsv()
    txtfile = admin.opentxt()
    for row in csvfile:
        record_uri = row[0]
        note_text = row[1]
        note_type = row[2]
        record_json = requests.get(values[0] + record_uri, headers=values[1]).json()
        new_note = {"jsonmodel_type": "note_multipart", 
                    "subnotes": [{'content': note_text, 'jsonmodel_type': 'note_text', 'publish': True}], 
                    'type': note_type, 'publish': True}
        try:
            record_json['notes'].append(new_note)
        except:
            print('note did not append')
        record_data = json.dumps(record_json)
        record_update = requests.post(values[0] + record_uri, headers=values[1], data=record_data).json()
        admin.writetxt(txtfile, record_update)
        print(record_update)
Пример #6
0
def replace_note_by_id():
    #replaces a note's content in ArchivesSpace using a persistent ID
    values = admin.login()
    csvfile = admin.opencsv()
    txtfile = admin.opentxt()
    for row in csvfile:
        resource_uri = row[0]
        persistent_id = row[1]
        note_text = row[2]
        resource_json = requests.get(values[0] + resource_uri, headers=values[1]).json()
        for note in resource_json['notes']:
            if note['jsonmodel_type'] == 'note_multipart':
                if note['persistent_id'] == persistent_id:
                    note['subnotes'][0]['content'] = note_text
            elif note['jsonmodel_type'] == 'note_singlepart':
                if note['persistent_id'] == persistent_id:
                    note['content'] = [note_text]
        resource_data = json.dumps(resource_json)
        resource_update = requests.post(values[0] + resource_uri, headers=values[1], data=resource_data).json()
        admin.writetxt(txtfile, resource_update)
        print(resource_update)
Пример #7
0
def create_rights_restrictions():
    values = admin.login()
    csvfile = admin.opencsv()
    txtfile = admin.opentxt()
    for row in csvfile:
        record_uri = row[0]
        persistent_id = row[1]
        begin = row[2]
        end = row[3]
        local_type = row[4]
        note_type = row[5]
        record_json = requests.get(values[0] + record_uri, headers=values[1]).json()
        new_restriction = {'begin': begin, 'end': end, 'local_access_restriction_type': [local_type],
                           'restriction_note_type': note_type, 'jsonmodel_type': 'rights_restriction'}
        for note in record_json['notes']:
            if note['persistent_id'] == persistent_id:
                note['rights_restriction'] = new_restriction
        record_data = json.dumps(record_json)
        record_update = requests.post(values[0] + record_uri, headers=values[1], data=record_data).json()
        admin.writetxt(txtfile, record_update)
        print(record_update)