Skip to content

Commit

Permalink
Merge pull request #88 from devketanpro/update_mapping_ritzau_ingest
Browse files Browse the repository at this point in the history
update categories mapping based on subjectID [BOR-23]
  • Loading branch information
devketanpro authored Oct 15, 2024
2 parents 55c92fc + 093320d commit 443a624
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions server/borsen/io/feed_parsers/ritzau.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ class RitzauFeedParser(BaseRitzauFeedParser):

def __init__(self):
super().__init__()
self.default_mapping.update({"anpa_category": {"xpath": "section/text()", "filter": self._category_filter}})
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 = {i["ritzau_section_id"].lower(): i for i in voc_categories if "ritzau_section_id" in i}
categories_cv = {str(i["ritzau_section_id"]): i for i in voc_categories if "ritzau_section_id" in i}
else:
categories_cv = {}

categories = [cat.strip().lower() for cat in category.split(",") if cat.strip()]
categories = [str(cat) for cat in category]

populated_categories = []
for cat in categories:
Expand Down
2 changes: 1 addition & 1 deletion server/tests/io/feed_parsers/ritzau_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_content(self):
{
"name": "bar",
"qcode": "f2",
"ritzau_section_id": "article",
"ritzau_section_id": 2,
"subject": "",
"translations": {"name": {"fr": "article-fr", "es": "article-es"}},
"scheme": "categories",
Expand Down
6 changes: 3 additions & 3 deletions server/tests/io/fixtures/vocabularies.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"type": "manageable",
"selection_type": "multi selection",
"unique_field": "qcode",
"init_version": 1,
"init_version": 2,
"items": [
{"is_active": true, "name": "foo", "qcode": "f1", "ritzau_section_id": "assignment", "subject": "", "translations": {"name": {"fr": "assignment-fr", "es": "assignment-es"}}},
{"is_active": true, "name": "bar", "qcode": "f2", "ritzau_section_id": "article", "subject": "", "translations": {"name": {"fr": "article-fr", "es": "article-es"}}}
{"is_active": true, "name": "foo", "qcode": "f1", "ritzau_section_id": 1, "subject": "", "translations": {"name": {"fr": "assignment-fr", "es": "assignment-es"}}},
{"is_active": true, "name": "bar", "qcode": "f2", "ritzau_section_id": 2, "subject": "", "translations": {"name": {"fr": "article-fr", "es": "article-es"}}}
],
"schema": {
"name": {"translate": true},
Expand Down

0 comments on commit 443a624

Please sign in to comment.