Skip to content

Instantly share code, notes, and snippets.

@anarchivist
Created December 23, 2009 21:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anarchivist/262826 to your computer and use it in GitHub Desktop.
Save anarchivist/262826 to your computer and use it in GitHub Desktop.
Provide statistics on files containing MARC/ISO2709 records (originally by Ed Summers)
#!/usr/bin/env python
# originally by edsu - original at http://inkdroid.org/bzr/bin/marc-tags
import pymarc
import sys
stats = {}
def tally(r):
for f in r.fields:
stats[f.tag] = stats.get(f.tag, 0) + 1
records = 0
for filename in sys.argv[1:]:
for r in pymarc.MARCReader(file(filename)):
records += 1
tally(r)
#pymarc.map_xml(get_stats, *sys.argv[1:])
for e in stats:
print "%s : %s" % (e, stats[e])
print "%s total records" % records
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment