-
Notifications
You must be signed in to change notification settings - Fork 0
/
HarvestController.py
39 lines (37 loc) · 2.12 KB
/
HarvestController.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
import metadataHarvestor
from odp.client import ODPClient
from odp.exceptions import ODPException
from dotenv import load_dotenv
import os
import pprint
class HarvestController:
def harvest_records(self):
#Harvest records from a file and push them to a an API
harvester = metadataHarvestor.MetadataHarvest()
load_dotenv(f'{os.getcwd()}/.env')
client = ODPClient(timeout=30)
records = harvester.get_records()
imported_rec = records[1]
json_rec = records[0]
for i in range(len(json_rec)):
try:
process_rec = imported_rec[i]
post_rec = json_rec[i]
#print(post_rec)
if process_rec['metadataStandardName'] == 'Datacite':
result = client.create_or_update_metadata_record('chief-directorate-oceans-and-coastal-research',
'marine-information-management-system-collection',
'saeon-datacite-4-3',
post_rec,
doi=str(post_rec['doi'].strip()))
pprint.pprint(result['errors'],indent=4)
elif process_rec['metadataStandardName'] == 'ISO19115':
result = client.create_or_update_metadata_record('chief-directorate-oceans-and-coastal-research',
'marine-information-management-system-collection',
'iso19115-saeon-profile',
post_rec,
doi=post_rec['doi'].strip(),
sid=post_rec['fileIdentifier'].strip())
pprint.pprint(result['errors'],indent=4)
except ODPException as e:
print(f"{e}: {e.error_detail}")