Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'issn': u'0001-0782',
'issns': [],
'langcode': u'eng',
'libcode': u'AU',
'oclc': u'(OCoLC)02103367',
'publisher': u'Association for Computing Machinery,',
'pubplace': u'[Baltimore] :',
'pubyear': u'-1959.',
'title':
u'Communications of the Association for Computing Machinery.'}
bib2marc = '''02457cas a2200601 a 4500001000700000005001700007008004100024010003100065035002300096040021100119012002100330016002000351016001800371016001800389019001200407022003900419030001100458032001700469035003500486042001400521050001600535060001800551082001800569049000900587210001600596222003000612245003100642246006200673246003300735260006200768300002500830310001200855362003200867530004400899530002400943650002800967650003200995650002801027710004101055770007401096776008501170776006501255776006501320780009601385850009501481856005201576891004701628891004101675891003801716891005101754891003801805994001201843\x1e402190\x1e20120821142139.0\x1e750806c19599999nyumr p 0 a0eng c\x1e \x1fa 61065941 \x1fzsc 76000456 \x1e \x1fa(OCoLC)ocm01514517\x1e \x1faMUL\x1fcMUL\x1fdNSD\x1fdDLC\x1fdNSD\x1fdOCL\x1fdDLC\x1fdNST\x1fdDLC\x1fdRCS\x1fdNST\x1fdDLC\x1fdAIP\x1fdDLC\x1fdAIP\x1fdNSD\x1fdAIP\x1fdNST\x1fdNSD\x1fdNST\x1fdNSD\x1fdNST\x1fdDLC\x1fdGUA\x1fdIUL\x1fdMYG\x1fdOCL\x1fdSYS\x1fdLYU\x1fdOCLCQ\x1fdWAU\x1fdNSD\x1fdCDS\x1fdLVB\x1fdCUS\x1fdCIT\x1fdOCLCQ\x1fdUKMGB\x1fdTUU\x1fdTULIB\x1e \x1fa3\x1fb3\x1fen\x1fj2\x1fk1\x1fm1\x1e7 \x1faC32640000\x1f2DNLM\x1e7 \x1fa012401138\x1f2Uk\x1e7 \x1fa011234768\x1f2Uk\x1e \x1fa2446101\x1e0 \x1fa0001-0782\x1fl0001-0782\x1fz0588-8069\x1f21\x1e \x1faCACMA2\x1e \x1fa126160\x1fbUSPS\x1e \x1fa(OCoLC)1514517\x1fz(OCoLC)2446101\x1e \x1fansdp\x1fapcc\x1e00\x1faQA76\x1fb.A772\x1e0 \x1faZ 699.A1 C734\x1e04\x1fa001.64/05\x1f219\x1e \x1faEAUU\x1e0 \x1faCommun. ACM\x1e 0\x1faCommunications of the ACM\x1e00\x1faCommunications of the ACM.\x1e3 \x1faCommunications of the Association for Computing Machinery\x1e30\x1faCommunications of the A.C.M.\x1e \x1fa[New York] :\x1fbAssociation for Computing Machinery,\x1fc1959-\x1e \x1fav. :\x1fbill. ;\x1fc28 cm.\x1e \x1faMonthly\x1e0 \x1faVol. 2, no. 11 (Nov. 1959)-\x1e \x1faAlso issued in microformats and online.\x1e \x1faAlso issued online.\x1e 0\x1faComputers\x1fvPeriodicals.\x1e 6\x1faOrdinateurs\x1fvPe\xcc\x81riodiques.\x1e 4\x1faComputers\x1fxPeriodicals.\x1e2 \x1faAssociation for Computing Machinery.\x1e0 \x1ftACMemberNet\x1fgJuly 1990-\x1fx1059-1192\x1fw(DLC) 96643236\x1fw(OCoLC)23369844\x1e1 \x1ftCommunications of the ACM (Online)\x1fx1557-7317\x1fw(DLC)sn 99034011\x1fw(OCoLC)38436103\x1e08\x1fiOnline version:\x1ftCommunications of the ACM\x1fw(OCoLC)564464960\x1e08\x1fiOnline version:\x1ftCommunications of the ACM\x1fw(OCoLC)605189967\x1e00\x1ftCommunications of the Association for Computing Machinery\x1fw(DLC)sf 84001031\x1fw(OCoLC)2103367\x1e \x1faAzTeS\x1faCCC\x1faCaBVa\x1faCaOTM\x1faDLC\x1faFU\x1faGU\x1faICL\x1faINS\x1faInU\x1faMH-SD\x1faMMeT\x1faMWelC\x1faMoKU\x1faNSyU\x1faPPiD\x1e41\x1fxhttp://www.acm.org/pubs/contents/journals/cacm/\x1e30\x1f9853\x1f81\x1fav.\x1fbno.\x1fu12\x1fvr\x1fi(year)\x1fj(month)\x1fwm\x1e40\x1f9863\x1f81.1\x1fa<1>-\x1fi<1958>-\x1fxprovisional\x1e41\x1f9863\x1f81.2\x1fa<43>\x1fb<1>\x1fi<2000>\x1fj<01>\x1e20\x1f9853\x1f82\x1fav.\x1fbno.\x1fu12\x1fvr\x1fi(year)\x1fj(month)\x1fwm\x1fx01\x1e41\x1f9863\x1f82.1\x1fa<48>\x1fb<1>\x1fi<2005>\x1fj<01>\x1e \x1faC0\x1fbEAU\x1e\x1d'''
bib2h1marc = '''00432cx a22001093 4500001000800000004000700008005001700015008003300032852010000065856013600165866002100301\x1e4800665\x1e402190\x1e20120821142139.0\x1e0101264u 8 1001uu 0901128\x1e8 \x1fbauin\x1fhAU Electronic journals\x1fzRemote access restricted to American University authorized users.\x1e4 \x1fuhttp://vg5ly4ql7e.search.serialssolutions.com/?V=1.0&N=250&L=VG5LY4QL7E&S=I_M&C=0001-0782\x1fzClick here to access the journal online.\x1e31\x1f80\x1fav.27 (1984) -\x1e\x1d'''
bib2h2marc = '''00313cy a22001213 4500001000800000004000700008005001700015008003300032014001500065014001400080852007800094866001900172\x1e8782951\x1e402190\x1e20090519073317.0\x1e0905194p 8 |000||eng1000000\x1e1 \x1faBHA8925001\x1e0 \x1fa003641501\x1e 1\x1fbwrlc stnc\x1fzHeld at WRLC Center; available for delivery (Library use only)\x1e31\x1f80\x1fav.2 (1959)-\x1e\x1d'''
bib2 = Bib(
metadata=bib2meta,
marc=pymarc.record.Record(data=bib2marc),
holdings=[
Holding(marc=pymarc.record.Record(data=bib2h1marc),
items=[Item()]),
Holding(marc=pymarc.record.Record(data=bib2h2marc),
items=[Item(), Item()])]
)
self.rset = RecordSet(bibs=[bib1, bib2])
def test_metadata_api(self, volume):
import pymarc
# For now, test for a valid response.
metadata = volume.metadata
assert type(metadata) == pymarc.record.Record
bib_format AS formatcode,
language AS langcode,
library_name AS libcode,
network_number AS oclc,
wrlcdb.getBibBlob(%s) AS marcblob
FROM bib_text, bib_master, library
WHERE bib_text.bib_id=%s
AND bib_text.bib_id=bib_master.bib_id
AND bib_master.library_id=library.library_id
AND bib_master.suppress_in_opac='N'"""
data = self._ask_oracle(query, params=[bibid, bibid], first=True)
if raw:
return data
try:
raw_marc = str(data.pop('marcblob'))
marc = pymarc.record.Record(data=raw_marc)
except IndexError:
"""Some MARC records cause string index error in PyMarc.
Skip them for now.
TODO: handle this error in a better manner"""
marc = None
bib = Bib(metadata=data, marc=marc)
return bib
if hasattr(rec[1], 'callNumber'):
holdmeta['callnum'] = rec[1].callNumber.rstrip('\x00')
else:
holdmeta['callnum'] = ''
holdmeta['location'] = rec[1].localLocation.rstrip('\x00')
if hasattr(rec[1], 'publicNote') and school == 'GT':
holdmeta['status'] = rec[1].publicNote.rstrip('\x00')
if hasattr(rec[1], 'publicNote') and school == 'GM':
holdmeta['note'] = rec[1].publicNote.rstrip('\x00')
if hasattr(rec[1], 'circulationData'):
holdmeta['status'] = rec[1].circulationData[0].availableNow
if holdmeta['status'] is True or\
holdmeta['status'] == ' AVAILABLE':
holdmeta['status'] = 'Not Charged'
holdmeta['item_status'] = 1
marc = pymarc.record.Record(zoom_record.data.
bibliographicRecord.encoding[1])
if marc['856']:
holdmeta['url'] = marc['856']['u']
holdmeta['msg'] = marc['856']['z']
holdings.append(holdmeta)
return holdings
if hasattr(zoom_record, 'data'):
marc = pymarc.record.Record(zoom_record.data)
if marc['856']:
holdmeta['url'] = marc['856']['u']
holdmeta['msg'] = marc['856']['z']
holdmeta['callnum'] = ''
holdmeta['status'] = ''
holdmeta['note'] = ''
holdmeta['item_status'] = 0
holdmeta['location'] = ''
def _one_to_marc(self, r):
"""
Converts one record to a pymarc.record.Record object. Returns
the object. Note that the III record number is stored in 907$a
and the database ID is stored in 907$b. Other metadata fields
are stored in 9XXs as needed, to ease conversion from MARC to
Solr.
"""
marc_record = pymarc.record.Record(force_utf8=True)
try:
control_fields = r.record_metadata.controlfield_set.all()
except Exception as e:
raise S2MarcError('Skipped. Couldn\'t retrieve control fields. '
'({})'.format(e), str(r))
for cf in control_fields:
try:
data = cf.get_data()
field = pymarc.field.Field(tag=cf.get_tag(), data=data)
marc_record.add_ordered_field(field)
except Exception as e:
raise S2MarcError('Skipped. Couldn\'t create MARC field '
'for {}. ({})'.format(cf.get_tag(), e), str(r))
try:
varfields = r.record_metadata.varfield_set\
.exclude(marc_tag=None)\
status = rec[1].publicNote.rstrip('\x00')
holdmeta['status'] = self.append_leading_year_digits(status)
if hasattr(rec[1], 'circulationData'):
try:
holdmeta['status'] = rec[1].circulationData[0].availableNow
date_obj = datetime.strptime(rec[1].circulationData[0]
.availablityDate,
'%Y-%m-%d %H:%M:%S')
holdmeta['status'] = date_obj.strftime("DUE %m-%d-%Y")
holdmeta['item_status'] = 0
except:
holdmeta['status'] = 'Not Charged'
if holdmeta['status'] is True or holdmeta['status'].strip() == 'AVAILABLE':
holdmeta['status'] = 'Not Charged'
holdmeta['item_status'] = 1
marc = pymarc.record.Record(zoom_record.data.
bibliographicRecord.encoding[1])
if marc['856']:
if 'www.loc.gov' not in marc['856']['u'] and 'jpg' not in marc['856']['u']:
holdmeta['url'] = marc['856']['u']
holdmeta['msg'] = marc['856']['z']
holdings.append(holdmeta)
return holdings
if hasattr(zoom_record, 'data'):
marc = pymarc.record.Record(zoom_record.data)
if marc['856']:
holdmeta = {}
holdmeta['url'] = marc['856']['u']
holdmeta['msg'] = marc['856']['z']
holdmeta['callnum'] = ''
holdmeta['status'] = ''
holdmeta['note'] = ''
def get_marc_blob(bibid):
query = """
SELECT wrlcdb.getBibBlob(%s) AS marcblob
from bib_master"""
cursor = connections['voyager'].cursor()
cursor.execute(query, [bibid])
row = cursor.fetchone()
raw_marc = str(row[0])
rec = pymarc.record.Record(data=raw_marc)
return rec
def get_z3950_bib_data(bibid, lib):
conn = None
res = []
id_list = []
bib = None
try:
conn = _get_z3950_connection(settings.Z3950_SERVERS[lib])
except:
return None
query = zoom.Query('PQF', '@attr 1=12 %s' % bibid.encode('utf-8'))
try:
res = conn.search(query)
for r in res:
bib = {}
rec = pymarc.record.Record(r.data.bibliographicRecord.encoding[1])
bib['LIBRARY_NAME'] = lib
bib['AUTHOR'] = rec.author()
bib['BIB_ID'] = bibid
bib['BIB_FORMAT'] = rec['000']
id_list.append({'BIB_ID': bibid, 'LIBRARY_NAME': lib})
bib['BIB_ID_LIST'] = id_list
if rec['250']:
bib['EDITION'] = rec['250']['a']
else:
bib['EDITION'] = None
bib['IMPRINT'] = rec['260'].format_field()
bib['LANGUAGE'] = rec['008'].value()[35:38]
if rec['856']:
bib['LINK'] = rec['856']['u']
else:
bib['LINK'] = []
def get_holding(self, bibid=None, zoom_record=None, school=''):
# This retrieves and parses both GM and GT z3950 responses, which are
# from different systems and have different elements. It would be
# simpler to have a different method for each school.
holdings = []
if bibid and not zoom_record:
zoom_record = self.zoom_record(bibid)
if hasattr(zoom_record, 'data') and hasattr(zoom_record.data,
'holdingsData'):
if school == 'GM':
marctags = pymarc.record.Record(zoom_record.data.bibliographicRecord.encoding[1])
try:
bibtag541a = marctags['541']['a']
except:
bibtag541a = ''
for rec in zoom_record.data.holdingsData:
holdmeta = {}
holdmeta['item_status'] = 0
holdmeta['callnum'] = ''
holdmeta['status'] = ''
holdmeta['url'] = ''
holdmeta['note'] = ''
holdmeta['msg'] = ''
holdmeta['location'] = ''
if hasattr(rec[1], 'callNumber'):
holdmeta['callnum'] = rec[1].callNumber.rstrip('\x00')
if school == 'GM':
def __init__(self, metadata={}, marc=None, holdings=[]):
assert isinstance(marc, pymarc.record.Record) or marc is None, \
'marc must be a pymarc Record object'
assert isinstance(holdings, list), \
'holdings must be a list of Holding objects'
assert all(isinstance(h, Holding) for h in holdings), \
'holdings must be a list of Holding objects'
assert isinstance(metadata, dict), 'metadata must be a dictionary'
super(Bib, self).__init__()
self._marc = marc
self._holdings = holdings
self._metadata = deepcopy(META_TEMPLATE_BIB)
self.metadata = metadata
self._altmeta = self.altmeta()