Skip to content

Instantly share code, notes, and snippets.

import sys
from pymarc import Record, MARCReader
reader = MARCReader(file(sys.argv[1]))
print "ALT LOOKUP, Provider, URL"
for rec in reader:
#!/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 / linked880iiixrec.py
Created October 29, 2010 00:47
Couple of functions for handling linked marc fields in iii xrecord format.
#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))
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 July 7, 2011 21:57
Summon API searches with Python
"""
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 / write_marc_from_xls.py
Created July 23, 2011 13:21
Create MARC records from a spreadsheet
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.
@lawlesst
lawlesst / library_reports_models.py
Created July 23, 2011 12:22
Sample Django models for library reports.
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 / read_bluebook.py
Created July 23, 2011 15:39
Simple csv reader.
import sys
import csv
csv_file = csv.DictReader(open(sys.argv[1]))
for row in csv_file:
print row['bluebook'], row['journal']
@lawlesst
lawlesst / ldf-hdt-heroku.md
Last active September 26, 2015 17:00
Notes on running ldf-server on Heroku with an HDT backend

September 25, 2015

Steps to run ldf-server on Heroku with an HDT backend.

  • Read the Node troubleshooting guide from Heroku for background.
  • Run the commands in the Start with a Blank Slate section of the guide.
  • Add package.json to your git repository if it isn't already.
  • For my project, I had to explicitly add hdt - 1.2.2 as a dependendency.

package.json

@lawlesst
lawlesst / petl.md
Last active September 27, 2015 00:12
Quick intro to petl for VIVO Apps & Tools working group.