telegram-python 0.4.0__tar.gz → 0.6.2__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,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: telegram-python
3
- Version: 0.4.0
3
+ Version: 0.6.2
4
4
  Summary: A Python package for sending Telegram messages
5
5
  Author: Tatiana
6
6
  Author-email: durachevska@ukr.net
@@ -13,8 +13,10 @@ Classifier: Programming Language :: Python :: 3.13
13
13
  Requires-Dist: requests (>=2.32.3,<3.0.0)
14
14
  Description-Content-Type: text/markdown
15
15
 
16
- poetry add telegram_python
16
+ poetry add telegram-python
17
17
 
18
- cd demo
19
- poe demo
18
+ from telegram_python import send
19
+ send("hello from updated....")
20
+
21
+ python demo.py
20
22
 
@@ -0,0 +1,6 @@
1
+ poetry add telegram-python
2
+
3
+ from telegram_python import send
4
+ send("hello from updated....")
5
+
6
+ python demo.py
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "telegram-python"
3
- version = "0.4.0"
3
+ version = "0.6.2"
4
4
  description = "A Python package for sending Telegram messages"
5
5
  authors = ["Tatiana <durachevska@ukr.net>"]
6
6
  readme = "README.md"
@@ -13,7 +13,8 @@ requests = "^2.32.3"
13
13
  requires = ["poetry-core"]
14
14
  build-backend = "poetry.core.masonry.api"
15
15
 
16
- packages = [{include = "telegram_python"}]
16
+ [[tool.poetry.packages]]
17
+ include = "telegram_python"
17
18
 
18
19
  [tool.setuptools.packages]
19
20
  find = {exclude = ["demo"]}
@@ -0,0 +1,49 @@
1
+ import requests
2
+ from datetime import datetime
3
+ import os
4
+ import logging
5
+
6
+ sound_start_hour = int(os.getenv("TELEGRAM_SOUND_START_HOUR", 9))
7
+ sound_end_hour = int(os.getenv("TELEGRAM_SOUND_END_HOUR", 18))
8
+ bot_token = os.getenv("TELEGRAM_BOT_TOKEN")
9
+ chat_id = os.getenv("TELEGRAM_CHAT_ID")
10
+
11
+ if not bot_token or not chat_id:
12
+ raise ValueError("Bot token or chat ID not set. Please check your .env file.")
13
+
14
+ logging.basicConfig(level=logging.INFO, filename="py_log.log",filemode="w",
15
+ format="%(asctime)s %(levelname)s %(message)s")
16
+
17
+ def send(message: str, parse_mode: str = "Markdown") -> None:
18
+ """
19
+ Відправляє повідомлення в Telegram: у робочий час — звичайне, у неробочий — беззвучне
20
+ """
21
+
22
+ now = datetime.now()
23
+ current_hour = now.hour
24
+ is_work_time = sound_start_hour <= current_hour < sound_end_hour
25
+
26
+ telegram_max_symbol = 4096
27
+ if len(message) > telegram_max_symbol:
28
+ message = message[:telegram_max_symbol]
29
+
30
+ try:
31
+ url = f"https://api.telegram.org/bot{bot_token}/sendMessage"
32
+ payload = {
33
+ "chat_id": chat_id,
34
+ "text": message,
35
+ "parse_mode": parse_mode,
36
+ "disable_notification": not is_work_time # Беззвучно, якщо не в робочий час
37
+ }
38
+ my_rez=requests.post(url, json=payload, timeout=10)
39
+
40
+ if my_rez.status_code == 200:
41
+ logging.info(f"Message sent successfully to chat_id={chat_id}")
42
+ else:
43
+ logging.error(f"Message sent with reason: {my_rez.reason}")
44
+
45
+ except requests.exceptions.RequestException as e:
46
+ logging.error(f"Error sending message: {e}") # помилки, пов’язані з HTTP-запитами
47
+ except Exception as e:
48
+ logging.error(f"Unexpected error: {e}")
49
+
@@ -1,4 +0,0 @@
1
- poetry add telegram_python
2
-
3
- cd demo
4
- poe demo
@@ -1,46 +0,0 @@
1
- import requests
2
- from datetime import datetime
3
- import os
4
- import logging
5
-
6
- start_hour = int(os.getenv("TELEGRAM_START_HOUR", 0))
7
- end_hour = int(os.getenv("TELEGRAM_END_HOUR", 24))
8
- bot_token = os.getenv("TELEGRAM_BOT_TOKEN")
9
- chat_id = os.getenv("TELEGRAM_CHAT_ID")
10
-
11
- if not bot_token or not chat_id:
12
- raise ValueError("Bot token or chat ID not set. Please check your .env file.")
13
-
14
- logging.basicConfig(level=logging.INFO, filename="py_log.log",filemode="w",
15
- format="%(asctime)s %(levelname)s %(message)s")
16
-
17
- def send(message: str) -> None:
18
- """
19
- Відправляє повідомлення в Telegram в заданий час (від 0 до 24).
20
- """
21
-
22
- now = datetime.now()
23
- current_hour = now.hour
24
- telegram_max_symbol = 4096
25
- if start_hour <= current_hour and current_hour < end_hour:
26
- try:
27
- if len(message) > telegram_max_symbol:
28
- message = message[:telegram_max_symbol]
29
- url = f"https://api.telegram.org/bot{bot_token}/sendMessage"
30
- payload = {
31
- "chat_id": chat_id,
32
- "text": message
33
- }
34
- my_rez=requests.post(url, json=payload, timeout=10)
35
-
36
- if my_rez.status_code == 200:
37
- logging.info(f"Message sent successfully to chat_id={chat_id}")
38
- else:
39
- logging.error(f"Message sent with reason: {my_rez.reason}")
40
-
41
- except requests.exceptions.RequestException as e:
42
- logging.error(f"Error sending message: {e}") # помилки, пов’язані з HTTP-запитами
43
- except Exception as e:
44
- logging.error(f"Unexpected error: {e}")
45
- else:
46
- logging.info(f"Current time ({current_hour}) is outside the allowed range ({start_hour}-{end_hour}).")