コード例 #1
0
def create_our_record(recid):
    old_record = get_record(recid)

    for subfield in old_record.find_subfields('100__u'):
        if subfield.value.lower() == 'lisbon, lifep':
            subfield.value = 'LIP, Lisbon'

    for subfield in old_record.find_subfields('700__u'):
        if subfield.value.lower() == 'lisbon, lifep':
            subfield.value = 'LIP, Lisbon'

    try:
        instances_100 = old_record['100']
    except KeyError:
        instances_100 = []

    try:
        instances_700 = old_record['700']
    except KeyError:
        instances_700 = []

    record = BibRecord(recid=recid)
    record['100'] = instances_100
    record['700'] = instances_700
    return record.to_xml()
コード例 #2
0
def create_our_record(recid, bibupload, bibupload2):
    old_record = get_record(recid)

    try:
        instances_084 = old_record['084']
    except KeyError:
        instances_084 = []

    to_remove_instances_650 = []


    modified = False
    for field in old_record['650']:
        if 'PACS' in field.get_subfield_values('2'):
            assert len(field.subfields) >= 2
            assert len(field.subfields) -1 == len(field.get_subfield_values('a'))
            to_remove_instances_650.append(field)
            for value in field.get_subfield_values('a'):
                sub_2 = BibRecordSubField(code='2', value='PACS')
                sub_a = BibRecordSubField(code='a', value=value)
                f = BibRecordField(subfields=[sub_2, sub_a])
                instances_084.append(f)
                modified = True

    if not modified:
        return None

    # Remove wrong indicator
    for field in instances_084[:]:
        if field.ind1 == '1' and field.ind2 == '7' \
                and 'PACS' in field.get_subfield_values('2'):
            field.ind1 = ' '
            field.ind2 = ' '

    record = BibRecord(recid=recid)
    record['084'] = set(instances_084)
    bibupload.add(record.to_xml())

    if to_remove_instances_650:
        record = BibRecord(recid=recid)
        record['650'] = to_remove_instances_650
        bibupload2.add(record.to_xml())
コード例 #3
0
def append_to_record(rec_id, doi, published_date):
    """Attempt to add a DOI to a record.

    Also adds 930 'Published' if not already there and
    adds the extrapolated PubNote data to 773.
    """
    record = get_record(recid=rec_id)
    new_record = BibRecord(rec_id)
    # make sure that there is no DOI for this record
    if not record_has_doi(record, rec_id, doi):
        # create new record with only 0247 field, that we will append
        # to the existing record with bibupload function
        new_field = new_record.add_field('0247_')
        new_field.add_subfield('2', 'DOI')
        new_field.add_subfield('a', doi.decode('utf-8'))

        _print('DOI to be added: ' + doi + ' to the record ' + str(rec_id), 3)

    if not is_marked_published(record):
        new_field_980 = new_record.add_field('980__')
        new_field_980.add_subfield('a', 'Published')

    append_773 = False
    field_773 = record.find_fields('773__')
    new_field_773 = create_pubnote(doi, published_date)
    if len(field_773) == 0:
        append_773 = True
        _print("No pubnote, adding field 773 to record...", 7)
    elif not is_pubnote_identical(field_773, new_field_773):
        append_773 = True
        _print(
            "Field 773 already exists for record, " +
            "differs from DOI extract", 3)
    else:
        _print(
            "Field 773 already exists, does not " + "contradict DOI extract.",
            6)

    if append_773:
        new_field = new_record.add_field('773__')
        for code, value in new_field_773.iteritems():
            new_field.add_subfield(code, value)

    field_260 = record.find_subfields("260__c")

    if len(field_260) == 0:
        # We add 260__c publication date
        new_field = new_record.add_field('260__')
        new_field.add_subfield("c", published_date)

    if len(new_record.record) > 1:
        return new_record.to_xml()
    else:
        return None
コード例 #4
0
def append_to_record(rec_id, doi, published_date):
    """Attempt to add a DOI to a record.

    Also adds 930 'Published' if not already there and
    adds the extrapolated PubNote data to 773.
    """
    record = get_record(recid=rec_id)
    new_record = BibRecord(rec_id)
    # make sure that there is no DOI for this record
    if not record_has_doi(record, rec_id, doi):
        # create new record with only 0247 field, that we will append
        # to the existing record with bibupload function
        new_field = new_record.add_field('0247_')
        new_field.add_subfield('2', 'DOI')
        new_field.add_subfield('a', doi.decode('utf-8'))

        _print('DOI to be added: ' + doi +
               ' to the record ' + str(rec_id), 3)

    if not is_marked_published(record):
        new_field_980 = new_record.add_field('980__')
        new_field_980.add_subfield('a', 'Published')

    append_773 = False
    field_773 = record.find_fields('773__')
    new_field_773 = create_pubnote(doi, published_date)
    if len(field_773) == 0:
        append_773 = True
        _print("No pubnote, adding field 773 to record...", 7)
    elif not is_pubnote_identical(field_773, new_field_773):
        append_773 = True
        _print("Field 773 already exists for record, " +
               "differs from DOI extract", 3)
    else:
        _print("Field 773 already exists, does not " +
               "contradict DOI extract.", 6)

    if append_773:
        new_field = new_record.add_field('773__')
        for code, value in new_field_773.iteritems():
            new_field.add_subfield(code, value)

    field_260 = record.find_subfields("260__c")

    if len(field_260) == 0:
        # We add 260__c publication date
        new_field = new_record.add_field('260__')
        new_field.add_subfield("c", published_date)

    if len(new_record.record) > 1:
        return new_record.to_xml()
    else:
        return None
コード例 #5
0
ファイル: apsharvest_engine.py プロジェクト: fschwenn/inspire
class APSRecord(object):
    """
    Class representing a record to harvest.
    """
    def __init__(self, recid=None, doi=None, date=None, last_modified=None):
        self.recid = recid
        self.doi = doi or get_doi_from_record(self.recid)
        self.date = date
        self.record = BibRecord(recid or None)
        self.last_modified = last_modified

    def add_metadata(self, marcxml_file):
        """
        Adds metadata from given file. Removes any DTD definitions
        and translates the metadata to MARCXML using BibConvert.
        """
        if marcxml_file:
            self.record = create_records_from_file(marcxml_file)
            if self.recid:
                self.record['001'] = [BibRecordControlField(str(self.recid))]

    def add_metadata_by_string(self, marcxml_text):
        """
        Adds metadata from given text.
        """
        if marcxml_text:
            self.record = create_records_from_string(marcxml_text)
            if self.recid:
                self.record['001'] = [BibRecordControlField(str(self.recid))]

    def add_fft(self, fulltext_file, hidden=True):
        """
        Adds FFT information as required from given fulltext.
        """
        fft = self.record.add_field("FFT__")
        fft.add_subfield('a', fulltext_file)

        if hidden:
            fft.add_subfield('t', CFG_APSHARVEST_FFT_DOCTYPE)
            fft.add_subfield('o', "HIDDEN")
        else:
            fft.add_subfield('t', "INSPIRE-PUBLIC")

    def to_xml(self):
        return self.record.to_xml()
コード例 #6
0
ファイル: apsharvest_engine.py プロジェクト: jmartinm/inspire
class APSRecord(object):
    """
    Class representing a record to harvest.
    """
    def __init__(self, recid, doi=None, date=None, last_modified=None):
        self.recid = recid
        self.doi = doi or get_doi_from_record(self.recid)
        self.date = date
        self.record = BibRecord(recid or None)
        self.last_modified = last_modified

    def add_metadata(self, marcxml_file):
        """
        Adds metadata from given file. Removes any DTD definitions
        and translates the metadata to MARCXML using BibConvert.
        """
        if marcxml_file:
            self.record = create_records_from_file(marcxml_file)
            if self.recid:
                self.record['001'] = [BibRecordControlField(str(self.recid))]

    def add_metadata_by_string(self, marcxml_text):
        """
        Adds metadata from given text.
        """
        if marcxml_text:
            self.record = create_records_from_string(marcxml_text)
            if self.recid:
                self.record['001'] = [BibRecordControlField(str(self.recid))]

    def add_fft(self, fulltext_file, hidden=True):
        """
        Adds FFT information as required from given fulltext.
        """
        fft = self.record.add_field("FFT__")
        fft.add_subfield('a', fulltext_file)

        if hidden:
            fft.add_subfield('t', CFG_APSHARVEST_FFT_DOCTYPE)
            fft.add_subfield('o', "HIDDEN")
        else:
            fft.add_subfield('t', "INSPIRE-PUBLIC")

    def to_xml(self):
        return self.record.to_xml()
コード例 #7
0
ファイル: add_doi.py プロジェクト: jmartinm/inspire-scripts
def append_doi(recID, doi):
    record = get_record(recid=recID)
    try:
        # make sure that there is no DOI for this record
        if record.find_subfields('0247_a'):
            messages.append('Record %s already has a doi' % recID)
            if record.find_subfields('0247_a')[0].value != doi:
                errors.append('DOI of %s record is different than the new doi (%s)!'
                              % (recID, doi))
        else:
            # create new record with only 0247 field, that we will append
            # to the existing record with bibupload function
            new_record = BibRecord(recID)
            new_field = new_record.add_field('0247_')
            new_field.add_subfield('a', doi.decode('utf-8'))
            new_field.add_subfield('2', 'DOI')

            messages.append('Successfully inserted the doi: ' + doi +
                            ' to the record ' + str(recID))

            return new_record.to_xml()
    except Exception, e:
        traceback.print_exc()
        errors.append('Unknown error: ' + repr(e))