-
Notifications
You must be signed in to change notification settings - Fork 0
/
browsePagesData.py
85 lines (73 loc) · 3.28 KB
/
browsePagesData.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os
import json
import datetime
from asnake.aspace import ASpace
repo = ASpace().repositories(2)
outDir = "/media/Library/SPEwww/spe_website/_data"
collectionsFile = os.path.join(outDir, "collections.json")
subjectsFile = os.path.join(outDir, "subjects.json")
with open(collectionsFile, 'r', encoding='utf-8', newline='') as f:
collections = json.load(collectionsFile)
with open(subjectsFile, 'r', encoding='utf-8', newline='') as f:
subjects = json.load(subjectsFile)
timestamp = datetime.datetime.fromtimestamp(datetime.datetime.now().timestamp()).strftime('%Y-%m-%dT%H:%M:%S+00:00')
for resource in repo.resources:
#resource = repo.resources(102)
if resource.publish == True:
print (resource.title)
collection = {}
collection["id"] = resource.id_0
collection["title"] = resource.title
collection["modified"] = timestamp
if "finding_aid_title" in dir(resource):
collection["filing_title"] = resource.finding_aid_title
else:
collection["filing_title"] = resource.finding_aid_title
collection["subjects"] = []
for note in resource.notes:
if "type" in dir(note):
if note.type == "abstract":
collection["abstract"] = " ".join(note.content)
for subjectURI in resource.subjects:
subject = subjectURI.reify()
if subject.source == "meg":
collection["subjects"].append(subject.title)
if not subject.title in subjects:
subjects.append(subject.title)
for date in resource.dates:
if date.date_type == "inclusive":
collection["date"] = date.begin
if "end" in dir(date):
collection["date"] = collection["date"] + "-" + date.end
collection["extent"] = []
for extent in resource.extents:
collection["extent"].append(extent.number + " " + extent.extent_type)
collection["dacs"] = True
if not "ead_id" in dir(resource):
collection["dacs"] = False
checkNotes = ["abstract", "accessrestrict", "acqinfo", "bioghist", "scopecontent", "arrangement"]
for noteName in checkNotes:
found = False
for note in resource.notes:
if "type" in dir(note):
if note.type == noteName:
found = True
if found == False:
collection["dacs"] = False
creator = False
for agent in resource.linked_agents:
if agent.role == "creator":
creator = True
if creator == False:
collection["dacs"] = False
previous = False
for oldCollection in collections:
if oldCollection["id"] = if collection["id"]:
previous= True
oldCollection = collection
if previous == False:
collections.append(collection)
with open(collectionsFile, 'w', encoding='utf-8', newline='') as f:
json.dump(collections, f, indent=4)
with open(subjectsFile, 'w', encoding='utf-8', newline='') as f:
json.dump(subjects, f, indent=4)