From 386f2f974b2facc309c59ef8b8efdaf62237a598 Mon Sep 17 00:00:00 2001 From: Petr Jasek Date: Thu, 12 Oct 2023 17:04:33 +0200 Subject: [PATCH] log each event id we process from onclusive so we can check logs in case some event is missing CPCN-380 --- server/planning/feed_parsers/onclusive.py | 46 ++++++++++--------- .../planning/feed_parsers/onclusive_tests.py | 7 ++- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/server/planning/feed_parsers/onclusive.py b/server/planning/feed_parsers/onclusive.py index 50ea82213..5539ec011 100644 --- a/server/planning/feed_parsers/onclusive.py +++ b/server/planning/feed_parsers/onclusive.py @@ -52,30 +52,34 @@ def can_parse(self, content): def parse(self, content, provider=None): all_events = [] - with open("/tmp/onclusive.txt", "+a") as debug_output: - for event in content: - print(event["itemId"], event["startDate"], event["summary"], file=debug_output) + for event in content: + logger.info( + "Parsing event id=%s updated=%s deleted=%s", + event["itemId"], + event["lastEditDateUtc"].split(".")[0], + event["deleted"], + ) - guid = "urn:onclusive:{}".format(event["itemId"]) + guid = "urn:onclusive:{}".format(event["itemId"]) - item = { - GUID_FIELD: guid, - ITEM_TYPE: CONTENT_TYPE.EVENT, - "state": CONTENT_STATE.INGESTED, - } + item = { + GUID_FIELD: guid, + ITEM_TYPE: CONTENT_TYPE.EVENT, + "state": CONTENT_STATE.INGESTED, + } - try: - self.set_occur_status(item) - self.parse_item_meta(event, item) - self.parse_location(event, item) - self.parse_event_details(event, item) - self.parse_category(event, item) - self.parse_contact_info(event, item) - all_events.append(item) - except EmbargoedException: - logger.info("Ignoring embargoed event %s", event["itemId"]) - except Exception as error: - logger.exception("error %s when parsing event %s", error, event["itemId"], extra=dict(event=event)) + try: + self.set_occur_status(item) + self.parse_item_meta(event, item) + self.parse_location(event, item) + self.parse_event_details(event, item) + self.parse_category(event, item) + self.parse_contact_info(event, item) + all_events.append(item) + except EmbargoedException: + logger.info("Ignoring embargoed event %s", event["itemId"]) + except Exception as error: + logger.exception("error %s when parsing event %s", error, event["itemId"], extra=dict(event=event)) return all_events def set_occur_status(self, item): diff --git a/server/planning/feed_parsers/onclusive_tests.py b/server/planning/feed_parsers/onclusive_tests.py index a48c85f8c..120933ab6 100644 --- a/server/planning/feed_parsers/onclusive_tests.py +++ b/server/planning/feed_parsers/onclusive_tests.py @@ -38,7 +38,12 @@ def setUp(self): self.parse("onclusive_sample.json") def test_content(self): - item = OnclusiveFeedParser().parse([self.data])[0] + with self.assertLogs("planning", level=logging.INFO) as logger: + item = OnclusiveFeedParser().parse([self.data])[0] + self.assertIn( + "INFO:planning.feed_parsers.onclusive:Parsing event id=4112034 updated=2022-05-10T12:14:34 deleted=False", + logger.output, + ) item["subject"].sort(key=lambda i: i["name"]) expected_subjects = [ {"name": "Law & Order", "qcode": "88", "scheme": "onclusive_categories"},