From 4f5d7404e3403f89a2c858ef697264826e99ae92 Mon Sep 17 00:00:00 2001 From: marwoodandrew Date: Wed, 27 Dec 2023 17:01:26 +1100 Subject: [PATCH] handle archived kills --- .../formatters/aap_apple_news_formatter.py | 4 +- .../transmitters/http_push_apple_news.py | 14 +++-- server/aap/tests/io/fixtures/dc_response.xml | 62 ------------------- 3 files changed, 12 insertions(+), 68 deletions(-) delete mode 100644 server/aap/tests/io/fixtures/dc_response.xml diff --git a/server/aap/publish/formatters/aap_apple_news_formatter.py b/server/aap/publish/formatters/aap_apple_news_formatter.py index f9d8e846c..d54c02ecd 100644 --- a/server/aap/publish/formatters/aap_apple_news_formatter.py +++ b/server/aap/publish/formatters/aap_apple_news_formatter.py @@ -93,7 +93,7 @@ def _remove_embeds(self, article, remove_keys): for key in remove_keys: article.get("associations", {}).pop(key, None) - if "refs" in article: + if article.get("refs") is not None: article["refs"] = [r for r in article.get("refs", []) if r["key"] != key] def _remove_unwanted_embeds(self, article): @@ -105,7 +105,7 @@ def _remove_unwanted_embeds(self, article): remove_keys = [] # can only handle pictures at the moment - for key, item in article.get("associations", {}).items(): + for key, item in (article.get("associations") or {}).items(): if key.startswith("editor_") and item.get("type") != 'picture': remove_keys.append(key) diff --git a/server/aap/publish/transmitters/http_push_apple_news.py b/server/aap/publish/transmitters/http_push_apple_news.py index 3ab1f5b59..c13cb421c 100644 --- a/server/aap/publish/transmitters/http_push_apple_news.py +++ b/server/aap/publish/transmitters/http_push_apple_news.py @@ -60,11 +60,17 @@ def _get_item(self, queue_item): ) def _get_original_guid(self, item): + """ + Chase up the rewrite list until we get to the orignal in either the archive or legal archive (if the item has + expired from production + :param item: + :return: + """ guid = item.get('rewrite_of', item.get('guid', item.get('item_id', None))) - for i in range(item.get('rewrite_sequence', 1)): - prev = get_resource_service('archive').find_one( - req=None, _id=guid - ) + for _i in range(item.get('rewrite_sequence', 1)): + prev = get_resource_service('archive').find_one(req=None, _id=guid) + if not prev: + prev = get_resource_service('legal_archive').find_one(req=None, _id=guid) if not prev or not prev.get('rewrite_of'): break guid = prev['rewrite_of'] diff --git a/server/aap/tests/io/fixtures/dc_response.xml b/server/aap/tests/io/fixtures/dc_response.xml deleted file mode 100644 index 3edfbb709..000000000 --- a/server/aap/tests/io/fixtures/dc_response.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - /archives/aapimage/search/?search[form][fulltext]={searchTerms} - AAP Image Pool - AAP Image Pool - archive - yes - - 584 - 1 - 1 - 500 - full - (ORIGINALTRANSMISSIONREFERENCE=5e17c05cb622e78f93f8eba7)&(MODDATE>20200108) - - - - - - - show_collections, sp_gateway - - - - 20200110 - 110918 - aapimage - aapfeed - 1 - 1 - 657x981 - p - 20200110 - ingest_no_news_value_priority.JPG - aapfeed - image - JPG - Testy McTest face - 5e17c05cb622e78f93f8eba7 - 20200110 - 110918 - Edited 10/01/2020 11:10:am (user1) - 5e17c05cb622e78f93f8eba7 Testy McTest face - 20200110 - 111027 - 1 - - - - - - \ No newline at end of file