mirror of
https://github.com/serega404/VodokanalBot.git
synced 2026-05-30 12:10:01 +03:00
Добавил поддежку прокси
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
[](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) для того что бы узнать подробности.
|
||||
|
||||
@@ -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:
|
||||
@@ -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()
|
||||
|
||||
|
||||
+2
-2
@@ -1,2 +1,2 @@
|
||||
requests
|
||||
beautifulsoup4
|
||||
requests[socks]
|
||||
beautifulsoup4
|
||||
|
||||
Reference in New Issue
Block a user