-
Notifications
You must be signed in to change notification settings - Fork 1
/
iiif_tei_illustrations.py
38 lines (31 loc) · 1.42 KB
/
iiif_tei_illustrations.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
import argparse
import csv
import os
import xml.etree.ElementTree as eT
# Arguments
parser = argparse.ArgumentParser()
parser.add_argument('--xml', default='../Encodage/engravings-catalogue/xml-files', type=str, help="Le chemin du dossier des fichiers xml à charger.")
parser.add_argument('--csv', default='../pliegos_iiif.csv', type=str, help="Le chemin du fichier CSV contenant les URI IIIF")
args = parser.parse_args()
# Conversion cvs > list
with open(args.csv) as csvFile:
csv_reader = csv.reader(csvFile)
list_rows = list(csv_reader)
# Parsing XML files
for xmlFile in os.listdir(args.xml):
if xmlFile.endswith('.xml'):
xml_path = os.path.join(args.xml, xmlFile)
ns = {'tei': 'http://www.tei-c.org/ns/1.0'}
eT.register_namespace('', 'http://www.tei-c.org/ns/1.0')
tree = eT.parse(xml_path)
root = tree.getroot()
for i in range(len(list_rows)):
for image in root.findall('.//tei:figure/tei:graphic', ns):
imgName = image.get('source')
coords = image.get('n')
coords = coords.replace(" ", "")
# Linking manifests with engravings' coordinates to TEI <graphic>
if imgName == list_rows[i][7]:
imgURI = list_rows[i][8][:46] + coords + list_rows[i][8][50:]
image.set('url', imgURI[29:])
tree.write(xml_path, encoding="UTF-8", xml_declaration=True)