本文整理汇总了Python中pymarc.Record.as_marc方法的典型用法代码示例。如果您正苦于以下问题:Python Record.as_marc方法的具体用法?Python Record.as_marc怎么用?Python Record.as_marc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymarc.Record
的用法示例。
在下文中一共展示了Record.as_marc方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_record
# 需要导入模块: from pymarc import Record [as 别名]
# 或者: from pymarc.Record import as_marc [as 别名]
def create_record(cls, work, annotator, force_create=False, integration=None):
"""Build a complete MARC record for a given work."""
if callable(annotator):
annotator = annotator()
if isinstance(work, BaseMaterializedWork):
pool = work.license_pool
else:
pool = work.active_license_pool()
if not pool:
return None
edition = pool.presentation_edition
identifier = pool.identifier
_db = Session.object_session(work)
record = None
existing_record = getattr(work, annotator.marc_cache_field)
if existing_record and not force_create:
record = Record(data=existing_record.encode('utf-8'), force_utf8=True)
if not record:
record = Record(leader=annotator.leader(work), force_utf8=True)
annotator.add_control_fields(record, identifier, pool, edition)
annotator.add_isbn(record, identifier)
# TODO: The 240 and 130 fields are for translated works, so they can be grouped even
# though they have different titles. We do not group editions of the same work in
# different languages, so we can't use those yet.
annotator.add_title(record, edition)
annotator.add_contributors(record, edition)
annotator.add_publisher(record, edition)
annotator.add_physical_description(record, edition)
annotator.add_audience(record, work)
annotator.add_series(record, edition)
annotator.add_system_details(record)
annotator.add_ebooks_subject(record)
data = record.as_marc()
if isinstance(work, BaseMaterializedWork):
setattr(pool.work, annotator.marc_cache_field, data)
else:
setattr(work, annotator.marc_cache_field, data)
# Add additional fields that should not be cached.
annotator.annotate_work_record(work, pool, edition, identifier, record, integration)
return record
示例2: open
# 需要导入模块: from pymarc import Record [as 别名]
# 或者: from pymarc.Record import as_marc [as 别名]
#-------------------------------------------------
f = open('ostinos.csv')
csv_f = csv.reader(f)
out = open ('osti_recs.csv', 'w')
data = csv.writer(out)
data.writerow(['Title', 'Author', 'Date', 'Subjects', 'Description', 'OstiID', 'DOI', 'Report Number', 'DOE Number', 'URL', ''])
marcOut = open('ostimarc.mrc', 'w')
dc = '{http://purl.org/dc/elements/1.1/}'
dcq = '{http://purl.org/dc/terms/}'
for number in csv_f:
ostiId = number[0]
marc = Record() # Create a new record for each loop.
tree = etree.parse('http://www.osti.gov/scitech/scitechxml?Identifier='+ ostiId+ '.xml')
for node in tree.iter():
if node.tag == dc + 'ostiId':
if node.text == ostiId:
o = node.getparent()
osti = o.getchildren()
getRecs(osti, data)
getMarc(osti, marc)
marcOut.write(marc.as_marc()) # Write each new record.
示例3: open
# 需要导入模块: from pymarc import Record [as 别名]
# 或者: from pymarc.Record import as_marc [as 别名]
#-------------------------------------------------
f = open('ostinos2.csv')
csv_f = csv.reader(f)
out = open ('osti_recs2.csv', 'w')
data = csv.writer(out)
data.writerow(['Title', 'Author', 'Date', 'Subjects', 'Description', 'OstiID', 'DOI', 'Report Number', 'DOE Number', 'URL', ''])
marcOut = open('ostimarc.mrc', 'a')
dc = '{http://purl.org/dc/elements/1.1/}'
dcq = '{http://purl.org/dc/terms/}'
for number in csv_f:
ostiId = number[0]
marc = Record()
results = requests.get('http://www.osti.gov/scitech/scitechxml?Identifier="' + ostiId + '"')
tree = etree.fromstring(results.content)
for node in tree.iter():
if node.tag == dc + 'identifierReport':
#if node.text == ostiId:
o = node.getparent()
osti = o.getchildren()
getRecs(osti, data)
getMarc(osti, marc)
marcOut.write(marc.as_marc())
示例4: book_to_mark21_file
# 需要导入模块: from pymarc import Record [as 别名]
# 或者: from pymarc.Record import as_marc [as 别名]
#.........这里部分代码省略.........
#ISBN - International Standard Book Number
isbn = models.Identifier.objects.filter(book=book).exclude(identifier='pub_id').exclude(identifier='urn').exclude(identifier='doi')
for identifier in isbn:
if book.book_type:
record.add_field(record_field('020',['#','#'],['a', str(identifier.value)+' '+book.book_type]))
else:
record.add_field(record_field('020',['#','#'],['a', str(identifier.value)]))
#Source of acquisition
try:
base_url = models.Setting.objects.get(group__name='general', name='base_url').value
except:
base_url='localhost:8000'
book_url = 'http://%s/editor/submission/%s/' % (base_url, book.id)
record.add_field(record_field('030',['#','#'],['b', book_url]))
# Main entry - Personal name
authors = book.author.all()
author_names=''
for author in authors:
auhtor_names=author_names+author.full_name()+' '
name=author.last_name+', '+author.first_name
if author.middle_name:
name=name+' '+author.middle_name[:1]+'.'
record.add_field(record_field('100',['1','#'],['a', name]))
#Title statement
title_words = (book.title).split(' ')
first_word = title_words[0]
if first_word.lower() == 'the':
record.add_field(record_field('245',['1','4'],['a', book.title,'c',author_names]))
else:
record.add_field(record_field('245',['1','0'],['a', book.title,'c',author_names]))
#Publication
try:
press_name = models.Setting.objects.get(group__name='general', name='press_name').value
except:
press_name=None
try:
city = models.Setting.objects.get(group__name='general', name='city').value
except:
city = None
publication_info=[]
if book.publication_date:
#Press' city
if city :
publication_info.append('a')
publication_info.append(str(city))
#Press' name
if press_name:
publication_info.append('b')
publication_info.append(str(press_name))
#Date of Publication
publication_info.append('c')
publication_info.append(str(book.publication_date))
record.add_field(record_field('260',['#','#'],publication_info))
#Physical details
if book.pages:
record.add_field(record_field('300',['#','#'],['a',str(book.pages)+' pages']))
#Content type
record.add_field(record_field('336',['#','#'],['a', 'text','2','rdacontent']))
#Media type
record.add_field(record_field('337',['#','#'],['a', 'unmediated','2','rdamedia']))
#Carrier type
record.add_field(record_field('338',['#','#'],['a', 'volume','2','rdacarrier']))
#Language note
if languages:
for lang in languages:
record.add_field(record_field('546',['#','#'],['a', lang.display]))
else:
record.add_field(record_field('546',['#','#'],['a', 'In English']))
press_editors = book.press_editors.all()
#editors
for editor in press_editors:
record.add_field(record_field('700',['1','#'],['a', '%s, %s' % (editor.last_name,editor.first_name),'e','Press editor']))
#Series
if book.series:
record.add_field(record_field('830',['#','0'],['a', book.series.name ]))
if book.series.editor:
record.add_field(record_field('700',['1','#'],['a', '%s, %s' % (book.series.editor.last_name,book.series.editor.first_name),'e','Series editor']))
#Add record to file
title= book.title
if not xml:
filename='book_'+str(book.id)+'_'+re.sub('[^a-zA-Z0-9\n\.]', '', title.lower())+'_marc21.dat'
file=handle_marc21_file(record.as_marc(),filename, book, owner)
else:
filename='book_'+str(book.id)+'_'+re.sub('[^a-zA-Z0-9\n\.]', '', title.lower())+'_marc21.xml'
content=record_to_xml(record, quiet=False, namespace=False)
file=handle_marc21_file(content,filename, book, owner)
return file.pk