From 31c5cd576356216474709c12dbd11be2f48a91bf Mon Sep 17 00:00:00 2001 From: Madison Swain-Bowden Date: Wed, 26 Oct 2022 13:54:51 -0700 Subject: [PATCH] Move metadata references to class level --- .../provider_api_scripts/wordpress.py | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/openverse_catalog/dags/providers/provider_api_scripts/wordpress.py b/openverse_catalog/dags/providers/provider_api_scripts/wordpress.py index 9dcb89d72..63efcdf20 100644 --- a/openverse_catalog/dags/providers/provider_api_scripts/wordpress.py +++ b/openverse_catalog/dags/providers/provider_api_scripts/wordpress.py @@ -26,6 +26,20 @@ class WordPressDataIngester(ProviderDataIngester): endpoint = f"https://{host}/photos/wp-json/wp/v2/photos" providers = {constants.IMAGE: prov.WORDPRESS_DEFAULT_PROVIDER} license_url = "https://creativecommons.org/publicdomain/zero/1.0/" + metadata_extras = [ + "aperture", + "camera", + "created_timestamp", + "focal_length", + "iso", + "shutter_speed", + ] + metadata_resource_mapping = { + "photo_category": "categories", + "photo_color": "colors", + "photo_orientation": "orientation", + "photo_tag": "tags", + } def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -148,30 +162,18 @@ def _get_title(image): def _get_metadata(media_data, media_details): raw_metadata = media_details.get("image_meta", {}) metadata, tags = {}, [] - extras = [ - "aperture", - "camera", - "created_timestamp", - "focal_length", - "iso", - "shutter_speed", - ] - for key in extras: + for key in WordPressDataIngester.metadata_extras: value = raw_metadata.get(key) if value not in [None, ""]: metadata[key] = value raw_related_resources = media_data.get("_embedded", {}).get("wp:term", []) - resource_mapping = { - "photo_category": "categories", - "photo_color": "colors", - "photo_orientation": "orientation", - "photo_tag": "tags", - } for resource_arr in raw_related_resources: for resource in resource_arr: - if (txy := resource.get("taxonomy")) in resource_mapping.keys(): - resource_key = resource_mapping[txy] + if ( + txy := resource.get("taxonomy") + ) in WordPressDataIngester.metadata_resource_mapping: + resource_key = WordPressDataIngester.metadata_resource_mapping[txy] resource_val = resource.get("name") if txy == "photo_tag": tags.append(resource_val)