1
0
mirror of https://github.com/serega404/VodokanalBot.git synced 2026-05-30 12:10:01 +03:00

Добавил поддежку прокси

This commit is contained in:
2026-05-21 00:15:01 +03:00
parent dde75d0ef8
commit 23ab8113cf
4 changed files with 50 additions and 8 deletions
+11 -3
View File
@@ -2,7 +2,7 @@
[![MIT License](https://img.shields.io/github/license/serega404/VodokanalBot)](https://github.com/serega404/VodokanalBot) [![MIT License](https://img.shields.io/github/license/serega404/VodokanalBot)](https://github.com/serega404/VodokanalBot)
### Запуск в Docker ## Запуск в Docker
``` Docker ``` Docker
docker volume create vodokanal_bot_data docker volume create vodokanal_bot_data
@@ -15,11 +15,19 @@ docker run -d --name VodokanalBot \
ghcr.io/serega404/vodokanalbot:main 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/) * [Requests](https://requests.readthedocs.io/en/latest/)
* [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/) * [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/)
### Лицензия ## Лицензия
Распространяется под MIT License. Смотри файл [`LICENSE`](./LICENSE) для того что бы узнать подробности. Распространяется под MIT License. Смотри файл [`LICENSE`](./LICENSE) для того что бы узнать подробности.
+16
View File
@@ -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:
+21 -3
View File
@@ -8,6 +8,7 @@ URL = os.environ.get('VODOKANAL_URL', 'http://www.tgnvoda.ru/avarii.php')
SEND_SILENT = os.environ.get('SEND_SILENT', False) SEND_SILENT = os.environ.get('SEND_SILENT', False)
TELEGRAM_TOKEN = os.environ.get('TELEGRAM_TOKEN', '') TELEGRAM_TOKEN = os.environ.get('TELEGRAM_TOKEN', '')
TELEGRAM_CHANNEL = os.environ.get('TELEGRAM_CHANNEL', '') TELEGRAM_CHANNEL = os.environ.get('TELEGRAM_CHANNEL', '')
PROXY_URL = os.environ.get('PROXY_URL', '')
if TELEGRAM_TOKEN == '': if TELEGRAM_TOKEN == '':
print("Telegram token is not set") print("Telegram token is not set")
@@ -17,6 +18,16 @@ if TELEGRAM_CHANNEL == '':
print("Telegram channel is not set") print("Telegram channel is not set")
exit() exit()
# Configure HTTP client
session = requests.Session()
if PROXY_URL != '':
session.proxies.update({
'http': PROXY_URL,
'https': PROXY_URL,
})
# Load database # Load database
db = None db = None
@@ -28,7 +39,7 @@ else:
# Get data # Get data
req = requests.get(URL) req = session.get(URL)
if (req.status_code != 200): if (req.status_code != 200):
print("Request error: " + str(req.status_code)) print("Request error: " + str(req.status_code))
@@ -52,7 +63,14 @@ print("The number of posts for this day:", len(elements))
# Send telegram message # Send telegram message
def send_message(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): if (req.status_code != 200):
print("Telegram request error: " + str(req.status_code)) print("Telegram request error: " + str(req.status_code))
exit() exit()
@@ -63,7 +81,7 @@ def send_message(message):
if db is not None: if db is not None:
diff = set(elements) - set(db) diff = set(elements) - set(db)
if diff == []: if not diff:
print("No new posts") print("No new posts")
exit() exit()
+1 -1
View File
@@ -1,2 +1,2 @@
requests requests[socks]
beautifulsoup4 beautifulsoup4