cli2telegram 2.0.1__tar.gz → 2.0.3__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.
@@ -1,32 +1,27 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: cli2telegram
3
- Version: 2.0.1
3
+ Version: 2.0.3
4
4
  Summary: Small utility to send Telegram messages from the CLI.
5
- Home-page: https://github.com/markusressel/cli2telegram
6
5
  License: AGPL-3.0-or-later
6
+ License-File: LICENSE
7
7
  Keywords: cli,telegram,notification
8
8
  Author: Markus Ressel
9
9
  Author-email: mail@markusressel.de
10
- Requires-Python: >=3.7,<4.0
10
+ Requires-Python: >=3.12,<4.0
11
11
  Classifier: Development Status :: 5 - Production/Stable
12
12
  Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
13
13
  Classifier: Programming Language :: Python :: 3
14
- Classifier: Programming Language :: Python :: 3.7
15
- Classifier: Programming Language :: Python :: 3.8
16
- Classifier: Programming Language :: Python :: 3.9
17
- Classifier: Programming Language :: Python :: 3.10
18
- Classifier: Programming Language :: Python :: 3.11
19
- Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Programming Language :: Python :: 3.15
20
18
  Classifier: Programming Language :: Python :: 3 :: Only
21
- Classifier: Programming Language :: Python :: 3.10
22
- Classifier: Programming Language :: Python :: 3.7
23
- Classifier: Programming Language :: Python :: 3.8
24
- Classifier: Programming Language :: Python :: 3.9
25
19
  Requires-Dist: aiofiles
26
20
  Requires-Dist: click
27
21
  Requires-Dist: container-app-conf
28
22
  Requires-Dist: emoji
29
23
  Requires-Dist: python-telegram-bot
24
+ Project-URL: Homepage, https://github.com/markusressel/cli2telegram
30
25
  Project-URL: Repository, https://github.com/markusressel/cli2telegram
31
26
  Description-Content-Type: text/markdown
32
27
 
@@ -35,8 +35,6 @@ CONFIG = Config(validate=False)
35
35
 
36
36
  CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
37
37
 
38
- loop = asyncio.get_event_loop()
39
-
40
38
 
41
39
  @click.command(context_settings=CONTEXT_SETTINGS)
42
40
  @click.option('-b', '--bot-token', 'bot_token', default=None, type=str, help='Telegram Bot Token')
@@ -92,11 +90,7 @@ def cli(bot_token: str or None, chat_id: str or None, code_block: bool, lines: T
92
90
 
93
91
  app = Application.builder().token(CONFIG.TELEGRAM_BOT_TOKEN.value).build()
94
92
 
95
- tasks = asyncio.gather(
96
- _send_messages(app, messages),
97
- )
98
-
99
- loop.run_until_complete(tasks)
93
+ asyncio.run(_send_messages(app, messages))
100
94
 
101
95
 
102
96
  def prepare_messages(text: str, code_block: bool) -> List[str]:
@@ -54,13 +54,13 @@ class Daemon:
54
54
  signal(SIGINT, self.signal_handler) # ctrl+c
55
55
  signal(SIGTERM, self.signal_handler) # systemctl stop
56
56
 
57
- loop = asyncio.get_event_loop()
58
- tasks = asyncio.gather(
57
+ asyncio.run(self._run_workers())
58
+
59
+ async def _run_workers(self):
60
+ await asyncio.gather(
59
61
  self.send_message_worker(),
60
62
  self.read_pipe_loop(),
61
63
  )
62
- loop.run_until_complete(tasks)
63
- loop.close()
64
64
 
65
65
  async def read_pipe_loop(self):
66
66
  LOGGER.info(f"Daemon is listening for input on {self.pipe_file_path}...")
@@ -18,6 +18,7 @@ import time
18
18
  from datetime import datetime, timedelta
19
19
 
20
20
  from telegram import Bot, InlineKeyboardMarkup, Message
21
+ from telegram.error import BadRequest, Forbidden, InvalidToken
21
22
  from telegram.ext import Application
22
23
 
23
24
  from cli2telegram import RetryLimitReachedException
@@ -88,11 +89,25 @@ async def try_send_message(
88
89
  :param give_up_after: when to give up trying
89
90
  """
90
91
  started_trying = datetime.now()
92
+ parse_mode = "markdown"
91
93
  success = False
92
94
  while not success:
93
95
  try:
94
- await send_message(bot=app.bot, chat_id=chat_id, message=message, parse_mode="markdown")
96
+ await send_message(bot=app.bot, chat_id=chat_id, message=message, parse_mode=parse_mode)
95
97
  success = True
98
+ except BadRequest as ex:
99
+ if parse_mode is not None and "parse entities" in str(ex).lower():
100
+ # characters like "_" or "*" in the text are not valid markdown, so send it as plain text
101
+ LOGGER.warning(f"Message is not valid markdown, sending it as plain text instead: {ex}")
102
+ parse_mode = None
103
+ continue
104
+ # the request itself is wrong, retrying would never help
105
+ LOGGER.exception(ex)
106
+ raise
107
+ except (InvalidToken, Forbidden) as ex:
108
+ # wrong token or the bot is not allowed to write to the chat, retrying would never help
109
+ LOGGER.exception(ex)
110
+ raise
96
111
  except Exception as ex:
97
112
  LOGGER.exception(ex)
98
113
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "cli2telegram"
3
- version = "2.0.1"
3
+ version = "2.0.3"
4
4
  description = "Small utility to send Telegram messages from the CLI."
5
5
 
6
6
  license = "AGPL-3.0-or-later"
@@ -20,10 +20,9 @@ classifiers = [
20
20
  "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
21
21
  "Programming Language :: Python :: 3 :: Only",
22
22
  "Programming Language :: Python :: 3",
23
- 'Programming Language :: Python :: 3.7',
24
- 'Programming Language :: Python :: 3.8',
25
- 'Programming Language :: Python :: 3.9',
26
- "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
25
+ "Programming Language :: Python :: 3.14",
27
26
  "Development Status :: 5 - Production/Stable"
28
27
  ]
29
28
 
@@ -32,7 +31,7 @@ requires = ["poetry-core>=1.0.0"]
32
31
  build-backend = "poetry.core.masonry.api"
33
32
 
34
33
  [tool.poetry.dependencies]
35
- python = "^3.7" # Compatible python versions must be declared here
34
+ python = "^3.12" # Compatible python versions must be declared here
36
35
 
37
36
  container-app-conf = "*"
38
37
  click = "*"
File without changes
File without changes