-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_metadata_availability.py
56 lines (45 loc) · 1.75 KB
/
check_metadata_availability.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
import de
import migration
def check_metadata_availability(de_link, username, password):
"""
Check the availability of metadata fields in a dataset, specifically title, author, and description.
Used to ensure that the most important pieces of metadata are available
for migration or for generating a Croissant/DCAT JSON-LD file.
Args:
de_link: The link to the dataset in the Discovery Environment.
username: The CyVerse username.
password: The CyVerse password.
Returns:
dict: A dictionary indicating the availability of metadata fields.
"""
token = de.get_de_api_key(username, password)
if token is None:
return "Error obtaining DE API key. Please check username and password."
headers = {'Authorization': f'Bearer {token}'}
path_parts = de_link.split('/')
directory_path = '/'.join(path_parts[:-1])
datasets = de.get_datasets(directory_path, headers)
if datasets is None:
return "Error obtaining datasets from the Discovery Environment."
for dataset in datasets:
if dataset['path'] == de_link:
dataset_metadata = de.get_all_metadata_dataset(dataset)
break
return_dict = {}
# Check the availability of title, author, and description
try:
migration.get_title(dataset_metadata)
return_dict["title"] = True
except Exception:
return_dict["title"] = False
try:
migration.get_author(dataset_metadata)
return_dict["author"] = True
except Exception:
return_dict["author"] = False
try:
migration.get_description(dataset_metadata)
return_dict["description"] = True
except Exception:
return_dict["description"] = False
return return_dict