Adds support for multiple targets

pull/1347/head
Diego Pedregal 2025-06-10 09:08:55 +02:00
parent b0a006b261
commit d2753402a1
1 changed files with 28 additions and 24 deletions

View File

@ -26,11 +26,13 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
from itertools import chain
# To use this service you will need a Clickatell account to which you can get # To use this service you will need a Clickatell account to which you can get
# your API_TOKEN at: # your API_TOKEN at:
# https://www.clickatell.com/ # https://www.clickatell.com/
import requests import requests
from itertools import chain
from .base import NotifyBase from .base import NotifyBase
from ..common import NotifyType from ..common import NotifyType
from ..locale import gettext_lazy as _ from ..locale import gettext_lazy as _
@ -190,38 +192,40 @@ class NotifyClickatell(NotifyBase):
url = self.notify_url.format(self.apikey) url = self.notify_url.format(self.apikey)
if self.source: if self.source:
url += '&from={}'.format(self.source) url += '&from={}'.format(self.source)
url += '&to={}'.format(','.join(self.targets)) url += '&to={to}'
url += '&content={}'.format(' '.join([title, body])) url += '&content={}'.format(' '.join([title, body]))
self.logger.debug('Clickatell GET URL: %s', url)
# Always call throttle before any remote server i/o is made # Always call throttle before any remote server i/o is made
self.throttle() self.throttle()
try: try:
r = requests.get( for target in self.targets:
url, new_url = url.format(to=target)
headers=headers, self.logger.debug('Clickatell GET URL: %s', new_url)
verify=self.verify_certificate, r = requests.get(
timeout=self.request_timeout, new_url,
) headers=headers,
verify=self.verify_certificate,
timeout=self.request_timeout,
)
if r.status_code != requests.codes.ok \ if r.status_code != requests.codes.ok \
and r.status_code != requests.codes.accepted: and r.status_code != requests.codes.accepted:
# We had a problem # We had a problem
status_str = self.http_response_code_lookup(r.status_code) status_str = self.http_response_code_lookup(r.status_code)
self.logger.warning( self.logger.warning(
'Failed to send Clickatell notification: ' 'Failed to send Clickatell notification: '
'{}{}error={}.'.format( '{}{}error={}.'.format(
status_str, status_str,
', ' if status_str else '', ', ' if status_str else '',
r.status_code)) r.status_code))
self.logger.debug('Response Details:\r\n{}'.format(r.content)) self.logger.debug(
return False 'Response Details:\r\n{}'.format(r.content))
else: return False
self.logger.info('Sent Clickatell notification.') else:
self.logger.info('Sent Clickatell notification.')
except requests.RequestException as e: except requests.RequestException as e:
self.logger.warning( self.logger.warning(