How to use the pymarc.Field 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 jermnelson / aristotle-library-apps / bibframe / ingesters / test_MARC.py View on Github external
def test_date2(self):
        # Authority Record
        record = pymarc.Record()
        record.add_field(pymarc.Field(tag='130',
                                      indicators=[' ', '0'],
                                      subfields=['f', '1902']))
        title_parser = MARC21toTitleEntity(redis_datastore=TEST_REDIS,
                                           record=record)
        title_parser.ingest()
        self.assertEquals(title_parser.title_entity.date,
                          ['1902'])
github edsu / pymarc / test / test_writer.py View on Github external
def test_writing_1_record(self):
        expected = r"""
            =LDR            22        4500
            =100  00$ame
            =245  00$aFoo /$cby me.
        """
        expected = textwrap.dedent(expected[1:])
        file_handle = StringIO()
        try:
            writer = pymarc.TextWriter(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()
github KnowledgeLinks / bibcat / tests / test_marc_ingester.py View on Github external
def setUp(self):
        self.marc_record = pymarc.Record()
        self.marc_record.add_field(
            pymarc.Field('245', 
                ['1', '0'],
                ['a', 'This is a test:',
                 'b', 'and subtitle']))
        self.ingester = marc.MARCIngester(record=self.marc_record)
github mattgrayson / iiitools / build / lib / iiitools.py View on Github external
raw_fields[-1]['value'] = "%s%s" % (raw_fields[-1]['value'], data)
                raw_fields[-1]['raw'] = "%s%s" % (raw_fields[-1]['raw'], field.strip())
            else:
                data = data if (tag < '010' and tag.isdigit()) else "a%s" % (data,)
                raw_fields.append({
                    'tag': tag, 
                    'indicator1': field[3], 
                    'indicator2': field[4], 
                    'value': data.strip(), 
                    'raw': field.strip()
                })
        
        for raw in raw_fields:
            tag = raw['tag']
            data = raw['value'].strip()
            field = Field(tag=tag, indicators=[raw['indicator1'], raw['indicator2']], data=data)
            if not field.is_control_field():
                for sub in data.split('|'):
                    try:
                        field.add_subfield(sub[0].strip(), sub[1:].strip())
                    except Exception:
                        # Skip blank/empty subfields
                        continue
            record.add_field(field)
            
        record.parse_leader()
        
        # Disregard record if no title present
        if not record.get_fields('245'):
            return None
        else:
            return record
github mediatum / mediatum / core / medmarc.py View on Github external
record = pymarc.Record()
    for field, subfields in sorted(fields.iteritems()):
        subfields = sorted(subfields.iteritems())

        # determine MARC field indicators
        ind1 = ind2 = '#'  # == "undefined"
        indicators = _indicators.get(field)
        if indicators:
            ind1, ind2 = indicators
            # support custom indicator value extraction functions (e.g. for URLs)
            if callable(ind1):
                ind1 = ind1(field, subfields)
            if callable(ind2):
                ind2 = ind2(field, subfields)

        record.add_field(pymarc.Field(
            field, indicators=[ind1, ind2], subfields=list(chain(* subfields))))

    # serialise
    return record.as_marc()
github jermnelson / aristotle-library-apps / marc_batch / jobs / ybp_ebrary.py View on Github external
def validate506(self,
                    marc_record):
        """
        Validates 506 field

        :param marc_record: Single MARC record
        """
        new506 = Field('506',
                       indicators=[' ',' '],
                       subfields=['a','Access restricted to subscribing institutions. Individual titles purchased upon selection by the 7th affiliated user.'])
        marc_record.add_field(new506)
        return marc_record
github jermnelson / aristotle-library-apps / marc_batch / jobs / ybp_ebl.py View on Github external
def validate710(self,marc_record):
        """Adds a 710 field if missing from marc_record.
       
        :param marc_record: Single MARC record
        """
        if not marc_record['710']:
	    field710 = Field('710',
                             indicators=['2',' '],
                             subfields=["a","Ebooks Corporation"])
            marc_record.add_field(field710)
        return marc_record
github jermnelson / Discover-Aristotle / aristotle / apps / marc / bots / video_bots.py View on Github external
def validate730(self,marc_record):
        """
        Method removes/replaces existing 730 with uniform title
        for Films on Demand

        :param marc_record: MARC record, required 
        """
        self.__remove_field__(marc_record=marc_record,
                              tag='730')
        field730 = Field(tag='730',
                         indicators=['0',' '],
                         subfields=['a','Films on Demand'])
        marc_record.add_field(field730)
        return marc_record
github slub / efre-lod-elasticsearch-tools / helperscripts / json2marc21.py View on Github external
def transpose_to_marc21(record):
    Mrecord=Record(force_utf8=True)
    Mrecord.leader=record["_LEADER"]
    for field in record:
        if isint(field):
            if int(field)<10:
                if isinstance(record[field],list):
                    for elem in record[field]:
                        Mrecord.add_field(Field(tag=field,data=elem))
                elif isinstance(record[field],str):
                    Mrecord.add_field(Field(tag=field,data=record[field]))
            else:
                for subfield in record[field]:
                    for ind, values in subfield.items():
                        indicators=[]
                        subfields=[]
                        for elem in values:
                            for k,v in elem.items():
                                if isinstance(v,str):
                                    subfields.append(k)
                                    subfields.append(v)
                                elif isinstance(v,list):
                                    for subfield_elem in v:
                                        subfields.append(k)
                                        subfields.append(subfield_elem)
github jermnelson / Discover-Aristotle / aristotle / apps / marc / bots / galebots.py View on Github external
:param marc_record:  MARC record, required
 
        '''
        field490s = marc_record.get_fields('490')
        field830s = marc_record.get_fields('830')
        if len(field490s) > 0:
            field490 = field490s[0]
            marc_record.remove_field(field490)
            if field490.get_subfields('a')[0] != self.series_statement:
                field490.delete_subfield('a')
                field490.add_subfield('a',self.series_statement)
            field490.indicators = None
            field490.indicators = ['1','\\']
        else:
            field490 = Field(tag='490',
                             indicators=['1','\\'],
                             subfields=['a',self.series_statement])
        if len(field830s) > 0:
            field830 = field830s[0]
            marc_record.remove_field(field830)
            if field830.get_subfields('a')[0] != self.series_statement:
                field830.delete_subfield('a')
                field830.add_subfield('a',self.series_statement)
            field830.indicators = ['\\','0']
        else:
            field830 = Field(tag='830',
                             indicators=['\\','0'],
                             subfields=['a',self.series_statement])
        marc_record.add_field(field490)
        marc_record.add_field(field830)
        return marc_record