Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
22 4500
me
Foo /
by me.
"""
expected = textwrap.dedent(expected[1:]).replace("\n", "").encode()
file_handle = BytesIO()
try:
writer = pymarc.XMLWriter(file_handle)
record = pymarc.Record()
record.add_field(pymarc.Field("100", ["0", "0"], ["a", "me"]))
record.add_field(
pymarc.Field("245", ["0", "0"], ["a", "Foo /", "c", "by me."])
)
writer.write(record)
writer.close(close_fh=False)
self.assertEquals(file_handle.getvalue(), expected)
finally:
file_handle.close()
def test_close_false(self):
"""If close_fh is false, then the file handle is NOT closed."""
file_handle = BytesIO()
self.assertFalse(file_handle.closed, "The file handle should be open")
writer = pymarc.XMLWriter(file_handle)
self.assertFalse(file_handle.closed, "The file handle should still be open")
writer.close(close_fh=False)
self.assertFalse(
file_handle.closed,
"The file handle should NOT close when the writer closes",
)
def test_close_true(self):
"""If close_fh is true, then the file handle is also closed."""
file_handle = BytesIO()
self.assertFalse(file_handle.closed, "The file handle should be open")
writer = pymarc.XMLWriter(file_handle)
self.assertFalse(file_handle.closed, "The file handle should still be open")
writer.close()
self.assertTrue(
file_handle.closed, "The file handle should close when the writer closes"
)
}
params = urlencode(params)
result = requests.get("https://sru.k10plus.de/k10plus?%s" % params)
result = result.text
result = result.replace("\n", "")
result = result.replace("", "\n")
return result.split("\n")
outputfilename = "183_output.xml"
if len(sys.argv) == 2:
outputfilename = sys.argv[1:]
writer = pymarc.XMLWriter(open(outputfilename, "wb"))
result = get_sru_records(1, 1)
n = result[0]
match = re.search("\(.*?)\", n)
if match:
all_records = match.group(1)
else:
sys.exit("could get numberOfRecords")
all_records = int(all_records)
max_records_request = 100
start = 1
while start < all_records:
oldrecords = get_sru_records(start, max_records_request)
"1.5": "809.9339"
}
# Keyword arguments
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-i", dest="inputfilename", help="inputfile", default="185_input.ndj", metavar="inputfilename")
parser.add_argument("-o", dest="outputfilename", help="outputfile", default="185_output.mrc", metavar="outputfilename")
parser.add_argument("-f", dest="outputformat", help="outputformat marc or marcxml", default="marc", metavar="outputformat")
args = parser.parse_args()
inputfilename = args.inputfilename
outputfilename = args.outputfilename
outputformat = args.outputformat
if outputformat == "marcxml":
outputfile = pymarc.XMLWriter(open(outputfilename, "wb"))
else:
outputfile = open(outputfilename, "wb")
inputfile = open(inputfilename, "r")
jsonrecords = inputfile.readlines()
for jsonrecord in jsonrecords:
jsonrecord = json.loads(jsonrecord)
marcrecord = marcx.Record(force_utf8=True)
marcrecord.strict = False
# Formatfestelegung
format = "Article"
# Leader
return ""
# Keyword arguments
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-i", dest="inputfilename", help="inputfile", default="188_input.xml", metavar="inputfilename")
parser.add_argument("-o", dest="outputfilename", help="outputfile", default="188_output.mrc", metavar="outputfilename")
parser.add_argument("-f", dest="outputformat", help="outputformat marc or marcxml", default="marc", metavar="outputformat")
args = parser.parse_args()
inputfilename = args.inputfilename
outputfilename = args.outputfilename
outputformat = args.outputformat
if outputformat == "marcxml":
outputfile = pymarc.XMLWriter(open(outputfilename, "wb"))
else:
outputfile = open(outputfilename, "wb")
inputfile = open(inputfilename, "r", encoding='utf-8')
xmlfile = inputfile.read()
xmlrecords = xmltodict.parse(
xmlfile,
force_list=["setSpec", "dc:identifier", "dc:creator", "dc:contributor", "dc:type", "dc:language", "dc:subject", "dc:publisher", "dc:date", "dc:title"])
for xmlrecord in xmlrecords["Records"]["Record"]:
marcrecord = marcx.Record(force_utf8=True)
marcrecord.strict = False
if xmlrecord["header"]["@status"] == "deleted":
continue
# Keyword arguments
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-i", dest="inputfilename", help="inputfile", default="186_input.xml", metavar="inputfilename")
parser.add_argument("-o", dest="outputfilename", help="outputfile", default="186_output.mrc", metavar="outputfilename")
parser.add_argument("-f", dest="outputformat", help="outputformat marc or marcxml", default="marc", metavar="outputformat")
args = parser.parse_args()
inputfilename = args.inputfilename
outputfilename = args.outputfilename
outputformat = args.outputformat
inputfile = open(inputfilename, "r")
if outputformat == "marcxml":
outputfile = pymarc.XMLWriter(open(outputfilename, "wb"))
else:
outputfile = open(outputfilename, "wb")
xmlfile = inputfile.read()
xmlrecords = xmltodict.parse(xmlfile, force_list=('field', ))
for xmlrecord in xmlrecords["collection"]["record"]:
marcrecord = marcx.Record(force_utf8=True)
marcrecord.strict = False
# Formatfestelegung
journal = get_field(xmlrecord, "78")
if journal:
format = "Article"
else:
import os
import sys
from io import BytesIO, StringIO
import marcx
import pymarc
from siskin.mappings import formats
from siskin.utils import marc_clean_record, xmlstream
input_directory = "input"
outputfilename = "183_output.xml"
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
##################################################################################
# 1. Parse arguments and prepare outputfile
##################################################################################
SID = "185"
args = get_arguments()
outputfilename = build_outputfilename(args, SID)
inputfilename = args.inputfilename
outputformat = args.outputformat
# Set output format for MARC record
if outputformat == "xml":
outputfile = pymarc.XMLWriter(open(outputfilename, "wb"))
else:
outputfile = open(outputfilename, "wb")
##################################################################################
# 2. Acquire input data
##################################################################################
if not inputfilename:
config = Config.instance()
inputfilename = config.get("dabi", "input")
inputfile = open(inputfilename, "r")
jsonrecords = inputfile.readlines()