-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfieldmap.py
44 lines (31 loc) · 889 Bytes
/
fieldmap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/env python3
import os
from collections import defaultdict
import lxml.etree
repo = "./data-import"
type_map = defaultdict(set)
def main():
filenames = [
os.path.join(repo, f)
for f in next(os.walk(repo), (None, None, []))[2]
if f.endswith(".xml")
]
for fname in filenames:
with open(fname) as f:
xml = f.read()
element = lxml.etree.fromstring(xml)
type_ = None
if element.xpath("./AuthorBio"):
type_ = 'artwork'
elif element.xpath("./eventCoorporation"):
type_ = 'exhibition'
else:
type_ = 'publication'
for node in element.iterchildren():
type_map[type_].add(node.tag)
for name, types in type_map.items():
print(f"Type: {name}")
print(types)
print()
if __name__ == "__main__":
main()