Created
December 24, 2009 17:17
-
-
Save anarchivist/263270 to your computer and use it in GitHub Desktop.
Match records in Horizon item/bib data and convert MARC to CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Use to extract records from SirsiDynix Horizon matching certain item/bib criteria */ | |
| SELECT DISTINCT item.bib# | |
| FROM item, bib WHERE bib.bib# = item.item# | |
| AND item.collection NOT IN ('oh', 'icos', 'mi') | |
| AND item.location = 'icos' | |
| AND (bib.text LIKE '%audio%' OR bib.text LIKE '%video%' | |
| OR bib.text LIKE '%cassette%' OR bib.text LIKE '%tape%' | |
| OR bib.text LIKE '%recording%' OR bib.text LIKE '%film%') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # convert MARC records into an ISO-8859-1 encoded CSV file | |
| from pymarc import MARCReader, marc8_to_unicode | |
| import csv, sys | |
| r = MARCReader(file(sys.argv[1])) | |
| w = open(sys.argv[2], 'wt') | |
| try: | |
| writer = csv.writer(w, lineterminator='\n') | |
| writer.writerow(('Bib #','Main Entry','Title')) | |
| for record in r: | |
| try: | |
| creator = marc8_to_unicode(record.author()) | |
| except: | |
| creator = u' ' | |
| creator = creator.encode('iso-8859-1', 'ignore') | |
| title = marc8_to_unicode(record['245'].formatField()) | |
| title = title.encode('iso-8859-1', 'ignore') | |
| writer.writerow((record['998']['b'], creator, title)) | |
| finally: | |
| w.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment