From 23ab8113cffd0ce2ce8d2c04c7a580d8973d0ae7 Mon Sep 17 00:00:00 2001 From: Sergey Karmanov Date: Thu, 21 May 2026 00:15:01 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D0=B6=D0=BA=D1=83=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=BA=D1=81=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 14 +++++++++++--- docker-compose.yml | 16 ++++++++++++++++ main.py | 24 +++++++++++++++++++++--- requirements.txt | 4 ++-- 4 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 docker-compose.yml diff --git a/README.md b/README.md index 8ee1a94..43a6ee9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![MIT License](https://img.shields.io/github/license/serega404/VodokanalBot)](https://github.com/serega404/VodokanalBot) -### Запуск в Docker +## Запуск в Docker ``` Docker docker volume create vodokanal_bot_data @@ -15,11 +15,19 @@ docker run -d --name VodokanalBot \ ghcr.io/serega404/vodokanalbot:main ``` -### Библиотеки +## Запуск в Docker Compose + +Укажи `TELEGRAM_TOKEN` и `TELEGRAM_CHANNEL` в [`docker-compose.yml`](./docker-compose.yml), затем запусти: + +``` Docker +docker compose up -d --build +``` + +## Библиотеки * [Requests](https://requests.readthedocs.io/en/latest/) * [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/) -### Лицензия +## Лицензия Распространяется под MIT License. Смотри файл [`LICENSE`](./LICENSE) для того что бы узнать подробности. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..630da02 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +services: + vodokanalbot: + image: ghcr.io/serega404/vodokanalbot:main + container_name: VodokanalBot + restart: always + environment: + TZ: Europe/Moscow + TELEGRAM_TOKEN: TOKEN + TELEGRAM_CHANNEL: CHAT_ID + # PROXY_URL: socks5h://user:password@proxy-host:1080 + # PROXY_URL: http://user:password@proxy-host:3128 + volumes: + - vodokanal_bot_data:/app/data + +volumes: + vodokanal_bot_data: diff --git a/main.py b/main.py index f19aa46..b522e81 100644 --- a/main.py +++ b/main.py @@ -8,6 +8,7 @@ URL = os.environ.get('VODOKANAL_URL', 'http://www.tgnvoda.ru/avarii.php') SEND_SILENT = os.environ.get('SEND_SILENT', False) TELEGRAM_TOKEN = os.environ.get('TELEGRAM_TOKEN', '') TELEGRAM_CHANNEL = os.environ.get('TELEGRAM_CHANNEL', '') +PROXY_URL = os.environ.get('PROXY_URL', '') if TELEGRAM_TOKEN == '': print("Telegram token is not set") @@ -17,6 +18,16 @@ if TELEGRAM_CHANNEL == '': print("Telegram channel is not set") exit() +# Configure HTTP client + +session = requests.Session() + +if PROXY_URL != '': + session.proxies.update({ + 'http': PROXY_URL, + 'https': PROXY_URL, + }) + # Load database db = None @@ -28,7 +39,7 @@ else: # Get data -req = requests.get(URL) +req = session.get(URL) if (req.status_code != 200): print("Request error: " + str(req.status_code)) @@ -52,7 +63,14 @@ print("The number of posts for this day:", len(elements)) # Send telegram message def send_message(message): - req = requests.get("https://api.telegram.org/bot" + TELEGRAM_TOKEN + "/sendMessage?chat_id=" + TELEGRAM_CHANNEL + "&disable_notification=" + str(SEND_SILENT) + "&text=" + message) + req = session.get( + "https://api.telegram.org/bot" + TELEGRAM_TOKEN + "/sendMessage", + params={ + 'chat_id': TELEGRAM_CHANNEL, + 'disable_notification': str(SEND_SILENT), + 'text': message, + }, + ) if (req.status_code != 200): print("Telegram request error: " + str(req.status_code)) exit() @@ -63,7 +81,7 @@ def send_message(message): if db is not None: diff = set(elements) - set(db) - if diff == []: + if not diff: print("No new posts") exit() diff --git a/requirements.txt b/requirements.txt index a98ae43..3ce5e1e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -requests -beautifulsoup4 \ No newline at end of file +requests[socks] +beautifulsoup4