How to use the pymarc.map_xml 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 edsu / pymarc / test / test_xml.py View on Github external
def test_multi_map_xml(self):
        self.seen = 0

        def count(record):
            self.seen += 1

        pymarc.map_xml(count, "test/batch.xml", "test/batch.xml")
        self.assertEqual(4, self.seen)
github edsu / pymarc / test / test_utf8.py View on Github external
def test_copy_utf8(self):
        writer = pymarc.MARCWriter(open("test/write-utf8-test.dat", "wb"))
        new_record = pymarc.Record(to_unicode=True, force_utf8=True)

        def process_xml(record):
            new_record.leader = record.leader

            for field in record.get_fields():
                new_record.add_field(field)

        pymarc.map_xml(process_xml, "test/utf8.xml")

        try:
            writer.write(new_record)
            writer.close()

        finally:
            # remove it
            os.remove("test/write-utf8-test.dat")
github edsu / pymarc / test / test_xml.py View on Github external
def test_map_xml(self):
        self.seen = 0

        def count(record):
            self.seen += 1

        pymarc.map_xml(count, "test/batch.xml")
        self.assertEqual(2, self.seen)
github edsu / pymarc / test / test_utf8.py View on Github external
def test_read_utf8(self):
        self.field_count = 0

        def process_xml(record):
            for field in record.get_fields():
                self.field_count += 1

        pymarc.map_xml(process_xml, "test/utf8.xml")
        self.assertEqual(self.field_count, 8)
github jakelever / pubrunner / pubrunner / convert.py View on Github external
def marcxml2bioc(marcxmlFilename,biocFilename):
	with open(marcxmlFilename,'rb') as inF, bioc.BioCXMLDocumentWriter(biocFilename) as writer:
		def marcxml2bioc_helper(record):
			writeMarcXMLRecordToBiocFile(record,writer)

		pymarc.map_xml(marcxml2bioc_helper,inF)
github LibraryOfCongress / chronam / chronam / web / holding_loader.py View on Github external
if record.leader[6] == 'y':
                    self.load_holding(record)

            except Exception, e:
                _logger.error("unable to load record %s: %s" % (self.records_processed, e))
                _logger.exception(e)
                self.errors += 1

            seconds = time() - t0
            times.append(seconds)

            if self.records_processed % 1000 == 0:
                _logger.info("processed %sk records in %.2f seconds" % 
                             (self.records_processed/1000, seconds))

        map_xml(load_record, file(filename, "rb"))
github jakelever / pubrunner / examples / SummaryData / summarizeMarcXML.py View on Github external
parser.add_argument('--oHasTitlesAndAbstracts',type=str,required=True,help="File containing counts of titles and abstracts")
	parser.add_argument('--oPubYear',type=str,required=True,help="File containing counts of publication years")
	parser.add_argument('--oJournals',type=str,required=True,help="File containing counts of journals")

	args = parser.parse_args()

	fTitles = codecs.open(args.oTitles,'w','utf-8')
	fHasTitlesAndAbstracts = codecs.open(args.oHasTitlesAndAbstracts,'w','utf-8')
	fPubYear = codecs.open(args.oPubYear,'w','utf-8')
	fJournals = codecs.open(args.oJournals,'w','utf-8')
	
	def summarizeMarcXMLFile_helper(record):
		summarizeMarcXMLFile(record,fTitles,fHasTitlesAndAbstracts,fPubYear,fJournals)

	with open(args.i,'rb') as inF:
		pymarc.map_xml(summarizeMarcXMLFile_helper,inF)