Skip to content

Commit

Permalink
Update ritzau.py
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanJelicSF authored Nov 7, 2024
1 parent 880ddb1 commit a37e820
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions server/borsen/io/feed_parsers/ritzau.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,30 @@ class RitzauFeedParser(BaseRitzauFeedParser):

def __init__(self):
super().__init__()
self.default_mapping.update({"anpa_category": {"xpath": "sectionID/text()", "filter": self._category_filter}})

def _category_filter(self, category):
voc_categories = superdesk.get_resource_service("vocabularies").get_items(_id="categories")
if voc_categories:
categories_cv = {str(i["ritzau_section_id"]): i for i in voc_categories if "ritzau_section_id" in i}
# Hardcode 'anpa_category' to 'CUSTOM' and set up 'anpa_section' to use the section filter
self.default_mapping.update({
"anpa_category": {"value": "Generelt"},
"anpa_section": {"xpath": "sectionID/text()", "filter": self._section_filter}
})

def _section_filter(self, section):
# Retrieve the vocabulary for sections
voc_sections = superdesk.get_resource_service("vocabularies").get_items(_id="sections")
if voc_sections:
# Map the vocabulary items using 'ritzau_section_id'
sections_cv = {str(i["ritzau_section_id"]): i for i in voc_sections if "ritzau_section_id" in i}
else:
categories_cv = {}
sections_cv = {}

categories = [str(cat) for cat in category]
# Convert each section to a string
sections = [str(sec) for sec in section]

populated_categories = []
for cat in categories:
match = categories_cv.get(cat)
populated_sections = []
for sec in sections:
match = sections_cv.get(sec)
if match:
populated_categories.append(match)
return populated_categories
populated_sections.append(match)
return populated_sections


register_feed_parser(RitzauFeedParser.NAME, RitzauFeedParser())

0 comments on commit a37e820

Please sign in to comment.