-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_collection.py
45 lines (31 loc) · 1018 Bytes
/
make_collection.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
45
import os
import json
import iiif_prezi3
iiif_prezi3.config.configs["helpers.auto_fields.AutoLang"].auto_lang = "en"
PREFIX = "https://data.globalise.huygens.knaw.nl/manifests/maps/"
def main(folder="maps"):
collection = iiif_prezi3.Collection(
id=f"{PREFIX}collection.json",
label="Overview of map collections",
)
# for json file in 'maps' folder
for f in os.listdir(folder):
if not f.endswith(".json"):
continue
file_path = os.path.join(folder, f)
with open(file_path) as infile:
c = json.load(infile)
c_id = c["id"]
c_type = c["type"]
c_label = c["label"]["en"][0]
collection.add_item(
iiif_prezi3.Reference(
id=c_id,
label=c_label,
type=c_type,
)
)
with open(os.path.join(folder, "collection.json"), "w") as outfile:
outfile.write(collection.json(indent=2))
if __name__ == "__main__":
main()