Exemplo n.º 1
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
Exemplo n.º 2
0
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'])
Exemplo n.º 3
0
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, [])
Exemplo n.º 4
0
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, [])
Exemplo n.º 5
0
def main():
    global d
    if not d:
        d = get_items('BARCD')
    total = float(len(d))
    i = 1
    fb = open(export_dir+'ITEMS.marc.dat', 'wb')
    ft = open(export_dir+'ITEMS.marc.txt', 'w')
    print 'Exporting items...'
    item_count = 0
    for (recid, copies) in d.items():
        if not is_staff_paper(recid):
            record = Record()
            id_field = Field(tag='999', indicators=[' ', ' '], subfields=['a', recid, 'b', ALL[recid].get('ID', '')])
            record.add_ordered_field(id_field)
            for c in copies.items():
                aux = [(e[0], items_fix[e[0]](e[1])) for e in c[1].items() if e[0] in items_fix]
                item_field = Field(tag='945', indicators=[' ', ' '], subfields= ['b', c[0]]+flatten_list(aux))
                record.add_ordered_field(item_field)
                item_count = item_count + 1
            fb.write(record.as_marc())
            ft.write(str(record) + '\n==================\n')
        update_progress(i*100/total)
        i = i + 1
    print "\nRecords:\t" + str(int(total))
    print "Items:  \t" + str(item_count)
    fb.close()
    ft.close()