Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Commit

Permalink
Move metadata references to class level
Browse files Browse the repository at this point in the history
  • Loading branch information
AetherUnbound committed Oct 26, 2022
1 parent b887048 commit 31c5cd5
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions openverse_catalog/dags/providers/provider_api_scripts/wordpress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 31c5cd5

Please sign in to comment.