From bbe4f7eb4d168669012939f50d683cb18d351dcd Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Tue, 16 Jan 2024 17:17:20 +0000 Subject: [PATCH] update --- msc_wis2node/publisher.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/msc_wis2node/publisher.py b/msc_wis2node/publisher.py index 79f75d9..fa974fe 100644 --- a/msc_wis2node/publisher.py +++ b/msc_wis2node/publisher.py @@ -105,11 +105,14 @@ def identify(self, path: str) -> Union[dict, None]: """ for dataset in self.datasets: - dirpath = self._subtopic2dirpath(dataset['subtopic']) - if dirpath.startswith(dirpath): + subtopic_dirpath = self._subtopic2dirpath(dataset['subtopic']) + + if path.startswith(subtopic_dirpath): LOGGER.debug('Found match') return dataset + LOGGER.debug('No match found') + return None def publish_to_wis2(self, dataset: str, url: str) -> None: @@ -132,23 +135,22 @@ def publish_to_wis2(self, dataset: str, url: str) -> None: url=url ) - print("MESSAGE", message) LOGGER.debug(json.dumps(message, indent=4)) LOGGER.info('Publishing WIS2 notification message') -# publish.single( -# topic, -# payload=json.dumps(message), -# qos=1, -# hostname=self.hostname, -# port=self.port, -# client_id=self.client_id, -# tls=self.tls, -# auth={ -# 'username': self.username, -# 'password': self.password -# } -# ) + publish.single( + topic, + payload=json.dumps(message), + qos=1, + hostname=self.hostname, + port=self.port, + client_id=self.client_id, + tls=self.tls, + auth={ + 'username': self.username, + 'password': self.password + } + ) def _subtopic2dirpath(self, subtopic: str) -> str: """ @@ -161,11 +163,12 @@ def _subtopic2dirpath(self, subtopic: str) -> str: LOGGER.debug(f'AMQP subtopic: {subtopic}') - dirpath = subtopic.replace('.', '/').rstrip('/#') + dirpath = '/' + subtopic.replace('.', '/').rstrip('/#') LOGGER.debug(f'directory path: {dirpath}') return dirpath def __repr__(self): + return ''