コード例 #1
0
ファイル: patrons.py プロジェクト: jgarcial/star_migration
def format_record(recid, record=None):
    if not record:
        record = ALL[str(recid)]
    if len(record):
        user_id = get_id(record)
        # uid = record.get('UID', '')
        # guid = record.get('GUID', '')
        # pa = record.get('PA', '')
        # user_id = uid
        # if len(user_id) != 6:
        #     user_id = guid
        # if len(user_id) != 6:
        #     user_id = pa
        # if len(user_id) != 6:
        #     user_id = uid
        #     if len(user_id) != 7:
        #         user_id = guid
        #     if len(user_id) != 7:
        #         user_id = pa
        #     if len(user_id) != 7:
        #         user_id = uid
                # print 'recno: %s\tuid: %s\tguid: %s\tpa: %s' % (recid, uid, guid, pa)
        template = {'tag': '999', 'ind1': ' ', 'ind2': ' ', 'subs': {'a' : user_id}}
        tags = []
        tags.append(Field(tag=template['tag'], indicators=[template['ind1'], template['ind2']], subfields=flatten_dict(template['subs'])))
        for (field, value) in record.items():
            if field in mapping:
                subfields = mapping[field](value)
                for template in subfields:
                    tags.append(Field(tag=template['tag'], indicators=[template['ind1'], template['ind2']], subfields=flatten_dict(template['subs'])))
        tags.sort()
        res = Record()
        for tag in tags:
            res.add_ordered_field(tag)
        return merge_subfields(res, ['101', '104', '110', '130', '400'])
コード例 #2
0
def format_record(recid, record=None):
    # print recid
    if not record:
        record = ALL[str(recid)]
    if len(record):
        mapping = reg_mapping
        if is_staff_paper(record):
            mapping = sp_mapping
        (collections, locations, formats) = index_record(record)
        tags = []
        for (field, value) in record.items():
            if field in mapping:
                try:
                    if field in ['TI', ]:
                        subfields = mapping[field](value, record.get('LANG'))
                    else:
                        subfields = mapping[field](value)
                except Exception as error:
                    # print "%s\t%s\t%s" % (recid, field, value)
                    # f = open('log.txt', 'a', "utf-8-sig")
                    with codecs.open(log_dir + 'log_bib.txt', 'a', encoding='utf8') as f:
                        f.write(("==================\n%s\nTI:\t%s\n%s:\t%s\n%s\n\n" % (recid, record['TI'], field, value, error)).replace('\n', '\r\n'))
                        f.close()

                    subfields = []
                for subfield in subfields:
                    tags.append(format_tag(subfield))
        tags.append(format_tag(mapping['RECID'](recid)[0]))
        tags.sort()
        res = Record(force_utf8=True, utf8_handling='ignore')
        # res = Record()
        for tag in tags:
            res.add_ordered_field(tag)
        res = merge_subfields(res, ['999', '998', '080', '773',])
        return res
コード例 #3
0
ファイル: serials.py プロジェクト: jgarcial/star_migration
def format_record(recid, record=None):
    if not record:
        record = ALL[str(recid)]
    if len(record):
        tags = []
        try:
            tags.append(Field(tag='999', indicators=[' ', ' '], subfields=['a', match_serial(record)]))
        except:
            with codecs.open(log_dir + 'unmatched_serials.txt', 'a', encoding='utf8') as f:
                f.write(recid + '\r\n')
                f.close()
        for (field, value) in record.items():
            if field in mapping:
                try:
                    subfields = mapping[field](value)
                    for template in subfields:
                        tags.append(Field(tag=template['tag'], indicators=[template['ind1'], template['ind2']], subfields=flatten_dict(template['subs'])))
                except:
                    with codecs.open(log_dir + 'log_serials.txt', 'a', encoding='utf8') as f:
                        f.write(("==================\n%s\n%s:\t%s\n\n" % (recid, field, record[field])).replace('\n', '\r\n'))
                        f.close()
        tags.sort()
        res = Record()
        for tag in tags:
            res.add_ordered_field(tag)
        return merge_subfields(res, [])
コード例 #4
0
ファイル: orders.py プロジェクト: jgarcial/star_migration
def format_record(recid, record=None):
    if not record:
        record = ALL[str(recid)]
    if len(record):
        tags = []
        for (field, value) in record.items():
            if field in mapping:
                subfields = mapping[field](value)
                for template in subfields:
                    tags.append(Field(tag=template['tag'], indicators=[template['ind1'], template['ind2']], subfields=flatten_dict(template['subs'])))
        tags.sort()
        res = Record()
        for tag in tags:
            res.add_ordered_field(tag)
        return merge_subfields(res, [])