Example #1
0
def main():

    # set to Prod | Dev | Test
    asf.setServer('Prod')

    bibid_file = "ead_bibids_20190520.txt"
    lookup_file = "id_lookup_prod_20190522.csv"
    outfile_loc = "ead_as_qc_reports/ead_as_qc_xml_PROD1"

    with open(bibid_file) as f:
        the_bibids = [line.rstrip('\n') for line in f]

    the_errors = []
    the_processed = []

    for a_bibid in the_bibids:
        print('Processing bibid: ' + a_bibid)
        if a_bibid:
            try:
                the_lookup = asf.lookupByBibID(a_bibid, lookup_file)
                the_repo = the_lookup[0]
                the_asid = the_lookup[1]
                the_processed.append(a_bibid)
            except:
                # Can't find in lookup
                the_repo = 0
                the_asid = 0
                the_errors.append(a_bibid)

        if (a_bibid and the_asid != 0):
            the_ead = asf.getEAD(the_repo, the_asid)

            the_filepath = outfile_loc + '/' + a_bibid + '_ead.xml'

            with open(the_filepath, "w") as myfile:
                myfile.write(the_ead)

    # Report results
    print('Processed ' + str(len(the_processed)) + ' records.')
    if len(the_errors) > 0:
        print('*** Warning: ' + str(len(the_errors)) +
              ' errors. Could not process id ' + ', '.join(the_errors) +
              ' ***')
Example #2
0
tree = et.parse(id_xml)
root = tree.getroot()

the_recs = root.findall('record')

the_ids = []

for a_rec in the_recs:
    i = a_rec.xpath('identifier/text()')

    asid = str(
        i[0].split('/')[-1]).rstrip()  # get the asid from the uri string.
    repo = str(
        i[0].split('/')[-3]).rstrip()  # get the repo from the uri string.
    bibid = a_rec.xpath('bibid/text()')[0]

    the_ids.append([repo, asid, bibid])

for x in the_ids:

    the_ead = asf.getEAD(x[0], x[1])

    out_path = output_folder + '/' + str(x[2]) + '_out.xml'

    # Save copy of existing object
    print('Saving data to ' + out_path + '....')

    f = open(out_path, "w+")
    f.write(the_ead)
    f.close()