Skip to content

Instantly share code, notes, and snippets.

@djpillen
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djpillen/95ca0232bcf1066567b5 to your computer and use it in GitHub Desktop.
Save djpillen/95ca0232bcf1066567b5 to your computer and use it in GitHub Desktop.
Find missing titles
import lxml
from lxml import etree
import os
from os.path import join
# Enter the path to the folder containing your EADs
path = 'path/to/EADs'
# Check each file in the EAD folder
for filename in os.listdir(path):
tree = etree.parse(join(path, filename))
for cs in tree.xpath("//dsc//*[starts-with(local-name(), 'c0')]"): # Check each <c0x> componenet
t = cs.xpath("./did[1]//unittitle/text()") # Check for a unittitle
subt = cs.xpath("./did[1]//unittitle/*/text()") # Check for a nested title within a unittitle
d = cs.xpath("./did[1]//unitdate/text()") # Check for a unitdate
titlepath = tree.getpath(cs)
if len(t) == 0 and len(subt) == 0 and len(d) == 0: # Output an error message if all possible titles are missing
print filename + ' is missing a component title at ' + titlepath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment