-
Notifications
You must be signed in to change notification settings - Fork 1
/
linked_art.py
65 lines (48 loc) · 1.6 KB
/
linked_art.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from cromulent.model import factory
import os
from os import walk
import json
import yaml
from yaml.loader import SafeLoader
from pathlib import Path
import patterns
# ===============================================
# settings.py in local dir
import settings
[objtype,config_file] = settings.transform()
with open(config_file) as f:
data = yaml.load(f, Loader=SafeLoader)
config = data[1]
# dir to store collection data files
directory = config["directory"]
b_mapped = directory + config["b_mapped"]
c_linked_art = directory + config["c_linked_art"]
factory.default_lang = config["default_lang"]
factory.base_url = config["base_url"]
globalvars = []
# read in config
with open('globalvars.yaml') as f:
data = yaml.load(f, Loader=SafeLoader)
globalvars = data
files = []
for (dirpath, dirnames, filenames) in walk(b_mapped):
files.extend(filenames)
break
files.sort()
# iterate over files in b_mapped
for file in files:
filename = os.path.basename(file)
print(filename)
with open(b_mapped + '/' + file) as json_file:
data = json.load(json_file)
if objtype == "digitalobject":
data = patterns.digital_object_pattern(data, globalvars)
elif objtype == "humanmadeobject":
data = patterns.humanmadeobject_pattern(data, globalvars)
elif objtype == "set":
data = patterns.set_pattern(data, globalvars)
la = factory.toString(data, compact=False)
# write linked art to file
f = open(c_linked_art + '/' + filename, "w")
f.write(la)
f.close()