diff --git a/server/borsen/io/feed_parsers/ritzau.py b/server/borsen/io/feed_parsers/ritzau.py index 63e4ab2..c19edcb 100644 --- a/server/borsen/io/feed_parsers/ritzau.py +++ b/server/borsen/io/feed_parsers/ritzau.py @@ -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())