-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
24 lines (21 loc) · 1.02 KB
/
utils.py
File metadata and controls
24 lines (21 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Utility functions for processing Europeana API responses
# Get the preferred translation or any if the preferred one is not available
def get_lang_or_any(map, lang="en"):
if map is None or len(map) == 0:
return []
return map.get(lang, next(iter(map.values())))
# Extract relevant data from the API response
def clean_data(item):
return {
"title": get_lang_or_any(item.get("dcTitleLangAware")) or ["???"],
"agent": get_lang_or_any(item.get("edmAgentLabelLangAware"))
or get_lang_or_any(item.get("dcCreatorLangAware")),
"description": get_lang_or_any(item.get("dcDescriptionLangAware")),
"concept": get_lang_or_any(item.get("edmConceptPrefLabelLangAware")),
"place": get_lang_or_any(item.get("edmPlaceLabelLangAware")),
"year": item.get("year")
or get_lang_or_any(item.get("edmTimespanLabelLangAware")),
"provider": item.get("dataProvider", []),
"preview": item.get("edmPreview", []),
"website": item.get("edmIsShownAt", []),
}