1
0
Fork 0
mirror of https://github.com/EDeev/npr_meteobot.git synced 2026-10-07 20:49:33 +03:00

Docker-образ бота с Chromium; прогноз: запуск Chrome по API Selenium 4 (executable_path/chrome_options убраны в 4.10)

This commit is contained in:
Деев Егор Викторович 2026-10-06 22:16:24 +03:00
parent 69830f156f
commit 111fda71b1
6 changed files with 70 additions and 2 deletions

5
.dockerignore Normal file
View file

@ -0,0 +1,5 @@
.git
.github
*.md
**/__pycache__
*.db

35
.github/workflows/docker.yml vendored Normal file
View file

@ -0,0 +1,35 @@
name: Docker
on:
push:
tags: ["v*"]
workflow_dispatch:
jobs:
image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/edeev/npr_meteobot
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest
- uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

14
Dockerfile Normal file
View file

@ -0,0 +1,14 @@
# Школьный Telegram-бот погоды и актировок Норильска (aiogram 2). pymorphy2 0.9 не работает на Python 3.11+
FROM python:3.10-slim
RUN apt-get update && apt-get install -y --no-install-recommends chromium chromium-driver \
&& rm -rf /var/lib/apt/lists/*
ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 \
CHROME_BIN=/usr/bin/chromium CHROMEDRIVER=/usr/bin/chromedriver
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY *.py schema.sql ./
# база подписок sub.db создаётся в томе /data из schema.sql
VOLUME ["/data"]
WORKDIR /data
CMD ["python", "/app/bot.py"]

View file

@ -3,6 +3,7 @@
[Русский](README.md) · **English** [Русский](README.md) · **English**
[![CI](https://github.com/EDeev/npr_meteobot/actions/workflows/ci.yml/badge.svg)](https://github.com/EDeev/npr_meteobot/actions/workflows/ci.yml) [![CI](https://github.com/EDeev/npr_meteobot/actions/workflows/ci.yml/badge.svg)](https://github.com/EDeev/npr_meteobot/actions/workflows/ci.yml)
[![Release](https://img.shields.io/github/v/release/EDeev/npr_meteobot)](https://github.com/EDeev/npr_meteobot/releases)
A Telegram bot for schoolchildren in the Norilsk industrial area: it sends class cancellations due to frost A Telegram bot for schoolchildren in the Norilsk industrial area: it sends class cancellations due to frost
and wind ("aktirovka") for the user's shift and district and shows the weather forecast. and wind ("aktirovka") for the user's shift and district and shows the weather forecast.
@ -25,6 +26,9 @@ BOT_TOKEN=token_from_BotFather python bot.py
The `sub.db` database is created on first run from `schema.sql`. Cancellations need Chrome: the The `sub.db` database is created on first run from `schema.sql`. Cancellations need Chrome: the
administration site is read with Selenium. administration site is read with Selenium.
**Docker:** `docker run -d -e BOT_TOKEN=token -v meteobot-data:/data ghcr.io/edeev/npr_meteobot` (same as
`git.deev.su/edeev/npr_meteobot`). Chromium for the forecast is in the image, `sub.db` lives in the `/data` volume.
## License ## License
School project (2022). The code is open for study; there is no separate license. School project (2022). The code is open for study; there is no separate license.

View file

@ -3,6 +3,7 @@
**Русский** · [English](README.en.md) **Русский** · [English](README.en.md)
[![CI](https://github.com/EDeev/npr_meteobot/actions/workflows/ci.yml/badge.svg)](https://github.com/EDeev/npr_meteobot/actions/workflows/ci.yml) [![CI](https://github.com/EDeev/npr_meteobot/actions/workflows/ci.yml/badge.svg)](https://github.com/EDeev/npr_meteobot/actions/workflows/ci.yml)
[![Release](https://img.shields.io/github/v/release/EDeev/npr_meteobot)](https://github.com/EDeev/npr_meteobot/releases)
Telegram-бот для школьников Норильского промышленного района: присылает актировки (отмену занятий Telegram-бот для школьников Норильского промышленного района: присылает актировки (отмену занятий
из-за мороза и ветра) для своей смены и района и показывает прогноз погоды. из-за мороза и ветра) для своей смены и района и показывает прогноз погоды.
@ -25,6 +26,9 @@ BOT_TOKEN=токен_от_BotFather python bot.py
База `sub.db` создаётся при первом запуске из `schema.sql`. Для актировок нужен Chrome: сайт База `sub.db` создаётся при первом запуске из `schema.sql`. Для актировок нужен Chrome: сайт
администрации читается через Selenium. администрации читается через Selenium.
**Docker:** `docker run -d -e BOT_TOKEN=токен -v meteobot-data:/data ghcr.io/edeev/npr_meteobot` (то же —
`git.deev.su/edeev/npr_meteobot`). Chromium для прогноза уже в образе, `sub.db` — в томе `/data`.
## Лицензия ## Лицензия
Школьный проект (2022). Код открыт для изучения, отдельной лицензии нет. Школьный проект (2022). Код открыт для изучения, отдельной лицензии нет.

10
info.py
View file

@ -1,6 +1,8 @@
# - * - coding: utf-8 - * - # - * - coding: utf-8 - * -
import os
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import requests, config import requests, config
@ -40,8 +42,12 @@ def weather(moment):
chrome_options = Options() chrome_options = Options()
chrome_options.add_argument("--headless") chrome_options.add_argument("--headless")
chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--no-sandbox')
chromedriver = 'chromedriver' chrome_options.add_argument('--disable-dev-shm-usage')
browser = webdriver.Chrome(executable_path=chromedriver, chrome_options=chrome_options) if os.environ.get('CHROME_BIN'):
chrome_options.binary_location = os.environ['CHROME_BIN']
# Selenium 4: драйвер — через Service, параметры executable_path/chrome_options убраны в 4.10
service = Service(os.environ.get('CHROMEDRIVER', 'chromedriver'))
browser = webdriver.Chrome(service=service, options=chrome_options)
# После успешного входа в систему переходим на страницу «Gismeteo» # После успешного входа в систему переходим на страницу «Gismeteo»
browser.get(f'https://www.gismeteo.ru/weather-norilsk-3957/{moment}') browser.get(f'https://www.gismeteo.ru/weather-norilsk-3957/{moment}')