How to use the pymarc.marcxml.parse_xml_to_array function in pymarc

To help you get started, we’ve selected a few pymarc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github miku / siskin / siskin / assets / 183 / 183_marcxml.py View on Github external
if len(sys.argv) == 3:
    input_directory, outputfilename = sys.argv[1:]

writer = pymarc.XMLWriter(open(outputfilename, "wb"))

for root, _, files in os.walk(input_directory):

    for filename in files:
        if not filename.endswith(".xml"):
            continue
        inputfilepath = os.path.join(root, filename)

        for oldrecord in xmlstream(inputfilepath, "record"):

            oldrecord = BytesIO(oldrecord)
            oldrecord = pymarc.marcxml.parse_xml_to_array(oldrecord)
            oldrecord = oldrecord[0]

            marcrecord = marcx.Record.from_record(oldrecord)
            marcrecord.force_utf8 = True
            marcrecord.strict = False

            try:
                marcrecord["245"]["a"]
            except:
                continue

            # Identifikator
            f001 = marcrecord["001"].data
            marcrecord.remove_fields("001")
            marcrecord.add("001", data="183-" + f001)