ix-notifiers 0.0.259196408__tar.gz → 0.0.1296513512__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 ix.ai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,16 +1,17 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ix-notifiers
3
- Version: 0.0.259196408
3
+ Version: 0.0.1296513512
4
4
  Summary: A python library for notifiers
5
5
  Home-page: https://gitlab.com/ix.ai/notifiers
6
6
  Author: ix.ai
7
7
  Author-email: docker@ix.ai
8
8
  License: MIT License
9
- Description: A python library for notifiers. Used in the ix.ai projects.
10
-
11
- Platform: UNKNOWN
12
9
  Classifier: Programming Language :: Python :: 3
13
10
  Classifier: License :: OSI Approved :: MIT License
14
11
  Classifier: Operating System :: OS Independent
15
12
  Requires-Python: >=3.6
16
13
  Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: requests>=2.31.0
16
+
17
+ A python library for notifiers. Used in the ix.ai projects.
@@ -4,4 +4,4 @@
4
4
 
5
5
  # These get overwritten at build time. See build.sh
6
6
  VERSION = '0.0'
7
- BUILD = '259196408'
7
+ BUILD = '1296513512'
@@ -12,7 +12,6 @@ class IxNotifiers():
12
12
  """ the IxNotifiers class """
13
13
 
14
14
  notifiers = [
15
- 'telegram',
16
15
  'gotify',
17
16
  'null',
18
17
  ]
@@ -40,7 +39,7 @@ class IxNotifiers():
40
39
  return: True if at least one notification channel was successful, False otherwise
41
40
  """
42
41
  success = False
43
- for notifier in self.registered:
42
+ for notifier in self.registered.items():
44
43
  log.debug(f'Sending notification to {notifier}')
45
44
  if self.registered[notifier].send(**kwargs) is True:
46
45
  success = True
@@ -90,7 +90,7 @@ class GotifyNotifier(Notifier):
90
90
 
91
91
  resp = None
92
92
  try:
93
- resp = requests.post(self.settings['url'], json=req_json, headers=headers)
93
+ resp = requests.post(self.settings['url'], json=req_json, headers=headers, timeout=60)
94
94
  except requests.exceptions.RequestException as e:
95
95
  # Print exception if reqeuest fails
96
96
  log.warning(self.redact(f'Could not connect to the Gotify server. The error: {e}'))
@@ -1,16 +1,17 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ix-notifiers
3
- Version: 0.0.259196408
3
+ Version: 0.0.1296513512
4
4
  Summary: A python library for notifiers
5
5
  Home-page: https://gitlab.com/ix.ai/notifiers
6
6
  Author: ix.ai
7
7
  Author-email: docker@ix.ai
8
8
  License: MIT License
9
- Description: A python library for notifiers. Used in the ix.ai projects.
10
-
11
- Platform: UNKNOWN
12
9
  Classifier: Programming Language :: Python :: 3
13
10
  Classifier: License :: OSI Approved :: MIT License
14
11
  Classifier: Operating System :: OS Independent
15
12
  Requires-Python: >=3.6
16
13
  Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: requests>=2.31.0
16
+
17
+ A python library for notifiers. Used in the ix.ai projects.
@@ -1,3 +1,4 @@
1
+ LICENSE
1
2
  README.md
2
3
  setup.py
3
4
  ix_notifiers/__init__.py
@@ -5,7 +6,6 @@ ix_notifiers/constants.py
5
6
  ix_notifiers/core.py
6
7
  ix_notifiers/gotify_notifier.py
7
8
  ix_notifiers/null_notifier.py
8
- ix_notifiers/telegram_notifier.py
9
9
  ix_notifiers.egg-info/PKG-INFO
10
10
  ix_notifiers.egg-info/SOURCES.txt
11
11
  ix_notifiers.egg-info/dependency_links.txt
@@ -0,0 +1 @@
1
+ requests>=2.31.0
@@ -5,7 +5,7 @@
5
5
  import setuptools
6
6
  from ix_notifiers import constants
7
7
 
8
- with open("README.md", "r") as fh:
8
+ with open("README.md", "r", encoding="utf-8") as fh:
9
9
  long_description = fh.read()
10
10
 
11
11
  setuptools.setup(
@@ -26,7 +26,6 @@ setuptools.setup(
26
26
  ],
27
27
  python_requires='>=3.6',
28
28
  install_requires=[
29
- 'python-telegram-bot>=13.1',
30
- 'requests>=2.25.0',
29
+ 'requests>=2.31.0',
31
30
  ],
32
31
  )
@@ -1,109 +0,0 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """ Telegram """
4
-
5
- import logging
6
- import time
7
- import telegram
8
- from .core import Notifier
9
-
10
- log = logging.getLogger(__package__)
11
-
12
-
13
- def start(**kwargs):
14
- """ Returns an instance of the TelegramNotifier """
15
- return TelegramNotifier(**kwargs)
16
-
17
-
18
- class TelegramNotifier(Notifier):
19
- """ The TelegramNotifier class """
20
- params = {
21
- 'token': {
22
- 'mandatory': True,
23
- 'redact': True,
24
- 'type': 'string',
25
- },
26
- 'chat_id': {
27
- 'mandatory': True,
28
- 'type': 'string',
29
- },
30
- 'parse_mode': {
31
- 'default': 'Markdown',
32
- 'type': 'string,'
33
- },
34
- 'max_retries': {
35
- 'default': 0,
36
- 'type': 'integer',
37
- },
38
- 'always_succeed': {
39
- 'default': False,
40
- 'type': 'boolean',
41
- },
42
- }
43
-
44
- def __init__(self, **kwargs):
45
- self.settings = {}
46
- super().__init__(**kwargs)
47
- self.notifier = telegram.Bot(token=self.settings['token'])
48
- log.debug(self.redact(f"Initialized with {self.settings}"))
49
-
50
- def send(self, **kwargs):
51
- """ sends a notification to telegram """
52
-
53
- # Allow per message override of parse_mode
54
- parse_mode = kwargs.get('parse_mode', self.settings['parse_mode'])
55
-
56
- retry = True
57
- success = True
58
- tries = 0
59
-
60
- # Telegram has a maximum message limit of 4096 characters
61
- if len(kwargs['message']) > 4096:
62
- success = False
63
- retry = False
64
- log.error(f"The Telegram message is too long ({len(kwargs['message'])} > 4096). Not sending.")
65
-
66
- while retry is True and (
67
- (self.settings['max_retries'] == 0) or (tries < self.settings['max_retries'])
68
- ):
69
- tries += 1
70
- try:
71
- self.notifier.sendMessage(
72
- chat_id=self.settings['chat_id'],
73
- text=kwargs['message'],
74
- parse_mode=parse_mode,
75
- disable_web_page_preview=True,
76
- )
77
- log.info("Sent message to telegram.")
78
- log.debug(f"Message: {kwargs['message']}")
79
- retry = False
80
- except (TimeoutError, telegram.error.TimedOut, telegram.error.RetryAfter) as error:
81
- try:
82
- retry_after = 0.5 + int(error.retry_after)
83
- except AttributeError:
84
- retry_after = 2
85
- if (self.settings['max_retries'] == 0) or (tries < self.settings['max_retries']):
86
- log.warning(f'Exception caught - retrying in {retry_after}s: {error}')
87
- time.sleep(retry_after)
88
- else:
89
- log.warning(f'Exception caught: {error}')
90
- success = False
91
- except (telegram.error.Unauthorized) as error:
92
- log.error(self.redact(f'{error} - check TELEGRAM_TOKEN - skipping retries.'))
93
- retry = False
94
- success = False
95
- except (telegram.error.BadRequest) as error:
96
- exit_message = ''
97
- if str(error) == 'Chat not found':
98
- exit_message = 'Check TELEGRAM_CHAT_ID - '
99
- exit_message = self.redact(f'{exit_message}Skipping retries. The exception: {error}')
100
- log.error(exit_message)
101
- retry = False
102
- success = False
103
- except Exception as error:
104
- log.error(self.redact(f"Failed to send message! Exception: {error}"))
105
- retry = False
106
- success = False
107
- if self.settings['always_succeed']:
108
- success = True
109
- return success
@@ -1,2 +0,0 @@
1
- python-telegram-bot>=13.1
2
- requests>=2.25.0