From f54ffa1e0fdb7100deea3db29da9defe3c92409d Mon Sep 17 00:00:00 2001 From: Petr Jasek Date: Tue, 4 Jun 2024 11:42:37 +0200 Subject: [PATCH 1/2] set expiry when parsing onclusive events CPCN-825 --- server/planning/feed_parsers/onclusive.py | 9 +++++++++ server/planning/feed_parsers/onclusive_tests.py | 2 ++ 2 files changed, 11 insertions(+) diff --git a/server/planning/feed_parsers/onclusive.py b/server/planning/feed_parsers/onclusive.py index 4b0b83d58..8b9e4025d 100644 --- a/server/planning/feed_parsers/onclusive.py +++ b/server/planning/feed_parsers/onclusive.py @@ -75,6 +75,7 @@ def parse(self, content, provider=None): self.parse_event_details(event, item) self.parse_category(event, item) self.parse_contact_info(event, item) + self.set_expiry(item, provider) all_events.append(item) except EmbargoedException: logger.info("Ignoring embargoed event %s", event["itemId"]) @@ -303,3 +304,11 @@ def parse_contact_info(self, event, item): existing_contact_id = bson.ObjectId(existing_contact["_id"]) get_resource_service("contacts").patch(existing_contact_id, data) item["event_contact_info"].append(existing_contact_id) + + def set_expiry(self, event, provider) -> None: + expiry_minutes = ( + int(provider.get("content_expiry") if provider else 0) + or int(app.config.get("INGEST_EXPIRY_MINUTES")) + or (60 * 24) + ) + event["expiry"] = event["dates"]["end"] + datetime.timedelta(minutes=(expiry_minutes)) diff --git a/server/planning/feed_parsers/onclusive_tests.py b/server/planning/feed_parsers/onclusive_tests.py index 6ace90170..79918b778 100644 --- a/server/planning/feed_parsers/onclusive_tests.py +++ b/server/planning/feed_parsers/onclusive_tests.py @@ -112,6 +112,8 @@ def test_content(self): item = OnclusiveFeedParser().parse([data])[0] self.assertEqual(item["occur_status"]["qcode"], "eocstat:eos3") + self.assertGreater(item["expiry"], item["dates"]["end"]) + def test_content_no_time(self): data = self.data.copy() data["time"] = "" From ac8bcbc034211fb7dbc29898d1ea5486e8c85efa Mon Sep 17 00:00:00 2001 From: Petr Jasek Date: Tue, 4 Jun 2024 15:03:31 +0200 Subject: [PATCH 2/2] fix mypy --- server/planning/feed_parsers/onclusive.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/planning/feed_parsers/onclusive.py b/server/planning/feed_parsers/onclusive.py index 8b9e4025d..a04fea917 100644 --- a/server/planning/feed_parsers/onclusive.py +++ b/server/planning/feed_parsers/onclusive.py @@ -308,7 +308,7 @@ def parse_contact_info(self, event, item): def set_expiry(self, event, provider) -> None: expiry_minutes = ( int(provider.get("content_expiry") if provider else 0) - or int(app.config.get("INGEST_EXPIRY_MINUTES")) + or int(app.config.get("INGEST_EXPIRY_MINUTES", 0)) or (60 * 24) ) event["expiry"] = event["dates"]["end"] + datetime.timedelta(minutes=(expiry_minutes))