import csv from utilities.utilities import EADDir def find_nested_tags(ead): results = [] for node in ead.tree.iter(): tag = node.tag if len(list(node)) != 1: continue if list(node)[0].tag == tag and not node.text.strip(): results.append([ead.filename, ead.tree.getpath(node), tag]) return results if __name__ == "__main__": e = EADDir() results = e.characterize_dir(find_nested_tags) with open("eads_with_nested_tags.csv", mode="wb") as f: writer = csv.writer(f) for result in results: writer.writerows(result)
import csv from utilities.utilities import EADDir def get_multiple_accruals(ead): accruals = ead.tree.xpath("//accruals") if len(accruals) > 1: return [ead.filename, "{} accruals".format(len(accruals))] return "" if __name__ == "__main__": ead_dir = EADDir() results = list(filter(None, ead_dir.characterize_dir(get_multiple_accruals))) with open("multiple_accruals.csv", mode="wb") as f: writer = csv.writer(f) writer.writerow(["filename", "accrual number"]) writer.writerows(results)
import csv from utilities.utilities import EADDir def get_multiple_accruals(ead): accruals = ead.tree.xpath("//accruals") if len(accruals) > 1: return [ead.filename, "{} accruals".format(len(accruals))] return "" if __name__ == "__main__": ead_dir = EADDir() results = list( filter(None, ead_dir.characterize_dir(get_multiple_accruals))) with open("multiple_accruals.csv", mode="wb") as f: writer = csv.writer(f) writer.writerow(["filename", "accrual number"]) writer.writerows(results)
from utilities.utilities import EADDir ead_dir = EADDir( input_dir= r"C:\Users\wboyle\PycharmProjects\without-reservations\Real_Masters_all") def fix_portions(ead): for did in ead.tree.xpath("//did"): physdescs = did.xpath("physdesc") # if len(physdescs) > 1: # if all([len(physdesc.xpath("extent")) > 0 for physdesc in physdescs]): # for physdesc in physdescs: # physdesc.attrib["altrender"] = "part" if len(physdescs) == 1: if any([tag.tag == "extent" for tag in list(physdescs[0])]): physdescs[0].attrib["altrender"] = "whole" def fix_lone_container_summaries(ead): for did in ead.tree.xpath("//did"): physdescs = did.xpath("physdesc") if len(physdescs) <= 1: continue last_extent_altrender = "" for i, physdesc in enumerate(physdescs): if len(list(physdesc)) != 1: last_extent_altrender = "" continue
from utilities.utilities import EADDir ead_dir = EADDir(input_dir=r"C:\Users\wboyle\PycharmProjects\without-reservations\Real_Masters_all") def fix_portions(ead): for did in ead.tree.xpath("//did"): physdescs = did.xpath("physdesc") # if len(physdescs) > 1: # if all([len(physdesc.xpath("extent")) > 0 for physdesc in physdescs]): # for physdesc in physdescs: # physdesc.attrib["altrender"] = "part" if len(physdescs) == 1: if any([tag.tag == "extent" for tag in list(physdescs[0])]): physdescs[0].attrib["altrender"] = "whole" def fix_lone_container_summaries(ead): for did in ead.tree.xpath("//did"): physdescs = did.xpath("physdesc") if len(physdescs) <= 1: continue last_extent_altrender = "" for i, physdesc in enumerate(physdescs): if len(list(physdesc)) != 1: last_extent_altrender = "" continue if physdesc[0].tag != "extent": last_extent_altrender = "" continue