Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pls adapt the NINJS outputformatter to provide better references for all renditions [SDCP-723] #2489

Merged
merged 10 commits into from
Nov 16, 2023
38 changes: 37 additions & 1 deletion superdesk/io/feed_parsers/ninjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def _transform_from_ninjs(self, ninjs):
item["associations"][key] = deepcopy(associated_item)

if ninjs.get("renditions"):
item["renditions"] = ninjs["renditions"]
item["renditions"] = self.parse_renditions(ninjs["renditions"])

if ninjs.get("located"):
item["dateline"] = {"located": {"city": ninjs.get("located")}}
Expand All @@ -146,6 +146,42 @@ def _transform_from_ninjs(self, ninjs):

return item

def parse_renditions(self, renditions):
rend = []
devketanpro marked this conversation as resolved.
Show resolved Hide resolved
for rendition_name, rendition_data in renditions.items():
parsed_rendition = {}

# Parse href
href = rendition_data.get("href", "")
if isinstance(href, str) and href:
parsed_rendition["href"] = href

# Parse width and height
width = rendition_data.get("width")
height = rendition_data.get("height")
if isinstance(width, int) and isinstance(height, int):
parsed_rendition["width"] = width
parsed_rendition["height"] = height

# Parse mimetype
mimetype = rendition_data.get("mimetype", "")
if isinstance(mimetype, str) and mimetype:
parsed_rendition["mimetype"] = mimetype

# Parse poi
poi = rendition_data.get("poi", {})
if isinstance(poi, dict) and "x" in poi and "y" in poi:
parsed_rendition["poi"] = {"x": poi["x"], "y": poi["y"]}

# Parse media
media = rendition_data.get("media", "")
if isinstance(media, str) and media:
parsed_rendition["media"] = media

if parsed_rendition:
rend.append({rendition_name: parsed_rendition})
return rend

def _format_qcodes(self, items):
subjects = []
for item in items:
Expand Down
Loading