Skip to content

Instantly share code, notes, and snippets.

View printllmc856.py
import sys
from pymarc import Record, MARCReader
reader = MARCReader(file(sys.argv[1]))
print "ALT LOOKUP, Provider, URL"
for rec in reader:
View write_excel_to_marc.py
#!/usr/bin/env python
import sys
from pymarc import Field, Reader, Record, MARCWriter
import xlrd
#script timer
import time
start_time = time.time()
@lawlesst
lawlesst / ldapBackEnd.py
Created Oct 19, 2010
For connecting Django auth to LDAP.
View ldapBackEnd.py
"""
Add below to settings.py
AUTHENTICATION_BACKENDS = (
'ldapBackend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
Requires python-ldap
@lawlesst
lawlesst / linked880iiixrec.py
Created Oct 29, 2010
Couple of functions for handling linked marc fields in iii xrecord format.
View linked880iiixrec.py
#pass in elementree tree obj
#pass call linked_value('245', subfields=['a', 'c'])
def linked_fields(self):
linked_fields = []
for field in self.var_fields:
rec_tag = field.findtext('MARCINFO/MARCTAG')
if '880' == rec_tag:
linked_fields.append((field.findall('MARCSUBFLD'), field))
View parse_mt_diss.py
from xml.etree.ElementTree import ElementTree
import urllib
source_url = 'http://etd.lib.montana.edu/etd/view/locations-markers.php'
source = urllib.urlopen(source_url)
tree = ElementTree()
doc = tree.parse(source)
print'<?xml version="1.0" encoding="UTF-8"?>'
@lawlesst
lawlesst / summon_search.py
Created Jul 7, 2011
Summon API searches with Python
View summon_search.py
"""
Search Summon API with Python.
See Dough Chesnut's Code4Lib mailing list post: http://serials.infomotions.com/code4lib/archive/2010/201010/2408.html
"""
import httplib2
import urllib
from datetime import datetime
import hmac
import base64
import hashlib
@lawlesst
lawlesst / library_reports_models.py
Created Jul 23, 2011
Sample Django models for library reports.
View library_reports_models.py
class Accession(models.Model):
"""Sample for recording library statistics.
Use indexes for faster query time.."""
number = models.CharField(max_length=15, primary_key=True)
created = models.DateField(db_index=True)
acquisition_method = models.CharField(max_length=50, db_index=True)
format = models.CharField(max_length=50, db_index=True)
location = models.CharField(max_length=50, db_index=True)
volumes = models.IntegerField()
@lawlesst
lawlesst / search_z3950.py
Created Jul 23, 2011
Sample Z39.50 search with Python.
View search_z3950.py
"""
Simple script to search a Z39.50 target using Python
and PyZ3950.
"""
from PyZ3950 import zoom
ISBNs = ['9781905017799', '9780596513986']
@lawlesst
lawlesst / write_marc_from_xls.py
Created Jul 23, 2011
Create MARC records from a spreadsheet
View write_marc_from_xls.py
import xlrd, sys
from pymarc import Field, Reader, Record, MARCWriter
#script timer
import time
start_time = time.time()
"""Script that reads data from an Excel sheet and converts the records to MARC format.
Sample incoming data is in Chinese, UTF 8. Would work for other languages as well.
View read_bluebook.py
import sys
import csv
csv_file = csv.DictReader(open(sys.argv[1]))
for row in csv_file:
print row['bluebook'], row['journal']