-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- відправка нотифікацій у телеграм-групу - не використовує python-telegram-bot - конфігурування регіонів для можливості фільтрації сповіщень (опціонально) - конфігурування часового поясу (опціонально, за змовчуванням Europe/Kyiv)
- Loading branch information
Showing
9 changed files
with
427 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
TOKEN=<TOKEN> | ||
CHAT_ID=<CHAT_ID> | ||
# URL of API with compatiable format with http://alerts.net.ua/explosives_statuses_v2.json, optional | ||
# URL=http://alerts.net.ua/explosives_statuses_v2.json | ||
# Timezone, optional, default Europe/Kiev | ||
# TIMEZONE=Europe/Kiev | ||
# List of regions to filter, don't use spaces, single line, optional | ||
# REGION_LIST="Одеська область","Київська область","Житомирська область","м. Київ","Львівська область" | ||
# Full list of regions: | ||
# "Сумська область", "Харківська область", "Донецька область", "Херсонська область", "Миколаївська область", | ||
# "Одеська область", "Київська область", "Житомирська область", "м. Київ", "Автономна Республіка Крим", | ||
# "Запорізька область", "Дніпропетровська область", "Хмельницька область", "Полтавська область", | ||
# "Львівська область", "Волинська область" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
name: Release image to GHCR | ||
on: | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
steps: | ||
- name: Check out repository code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-tags: True | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.12" | ||
|
||
- name: Install dependencies | ||
run: | | ||
$(cat Dockerfile | grep "pip install" | cut -f2- -d " ") | ||
- name: Install pylint | ||
run: | | ||
python -m pip install pylint==3.1.0 black==24.3.0 | ||
# - name: Lint Python code with black | ||
# run: | | ||
# black --check --skip-string-normalization --line-length 120 bot | ||
|
||
- name: Lint Python code | ||
run: | | ||
pylint --disable=R,C,W1203,W0105 bot/main.py | ||
- name: Lint Dockerfile with hadolint | ||
uses: hadolint/[email protected] | ||
with: | ||
dockerfile: Dockerfile | ||
failure-threshold: error | ||
ignore: DL3008,SC3009,DL3013 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Bump version and push tag | ||
id: tag_version | ||
uses: mathieudutour/[email protected] | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
default_bump: minor | ||
|
||
- name: Login to GitHub Container Registry | ||
# do this step only on push to main and do not run for pull request | ||
if: github.event_name == 'push' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build Docker image and push to registry | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
# push to registry when merge to main | ||
push: ${{ github.ref == 'refs/heads/main' }} | ||
no-cache: true | ||
tags: | | ||
ghcr.io/yurnov/explosion-notifier:master | ||
ghcr.io/yurnov/explosion-notifier:${{ steps.tag_version.outputs.new_tag }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
name: Run tests and build Docker image for development version | ||
on: | ||
push: | ||
branches: | ||
- 'dev*' | ||
|
||
jobs: | ||
development: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
permissions: | ||
packages: write | ||
|
||
steps: | ||
- name: Check out repository code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-tags: True | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
|
||
- name: Install dependencies | ||
run: | | ||
$(cat Dockerfile | grep "pip install" | cut -f2- -d " ") | ||
- name: Install linters | ||
run: | | ||
python -m pip install pylint==3.1.0 black==24.3.0 | ||
# - name: Lint Python code with black | ||
# run: | | ||
# black --check --skip-string-normalization --line-length 120 bot | ||
|
||
- name: Lint Python code with Pylint | ||
run: | | ||
pylint --disable=R,C,W1203,W0105 bot/main.py | ||
- name: Lint Dockerfile with hadolint | ||
uses: hadolint/[email protected] | ||
with: | ||
dockerfile: Dockerfile | ||
failure-threshold: error | ||
ignore: DL3008,SC3009,DL3013 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to GitHub Container Registry | ||
# do this step only on push to main and do not run for pull request | ||
if: github.event_name == 'push' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build Docker image for development version and push to registry | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
# push to registry when merge to branch starting with dev | ||
push: ${{ startsWith(github.ref, 'refs/heads/dev') }} | ||
no-cache: true | ||
tags: ghcr.io/yurnov/explosion-notifier:dev | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM python:3.12-slim | ||
|
||
LABEL org.opencontainers.image.authors="Yuriy Novostavskiy" \ | ||
org.opencontainers.image.source="https://github.com/yurnov/ua-explosion-notification-bot.git" \ | ||
org.opencontainers.image.license="MIT" \ | ||
org.opencontainers.image.description="A simple bot that sends the update of alarms and exlosions" | ||
|
||
RUN python -m pip install requests~=2.31.0 python-dotenv~=1.0.1 pytz==2024.1 | ||
|
||
WORKDIR /bot | ||
|
||
COPY bot/* ./ | ||
|
||
ENTRYPOINT [ "python", "main.py" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM python:3.12-slim | ||
|
||
RUN python -m pip install requests~=2.31.0 python-dotenv~=1.0.1 pytz==2024.1 black==24.3.0 pylint==3.1.0 | ||
|
||
CMD [ "black", "--skip-string-normalization", "--line-length", "120", "bot" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Відправка повідомлень у телеграм-групу при появі повідомлень про вибухи у ЗМІ | ||
![python-version](https://img.shields.io/badge/python-3.12-blue.svg) | ||
[![license](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) | ||
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) | ||
|
||
Невеликий [Telegram bot](https://core.telegram.org/bots/api) що працює у Docker контейнері і потребує мінімальну конфігурацію. Джерелом даних є сервер даних [Сервер даних JAAM](http://alerts.net.ua/). | ||
|
||
## Що потрібно для роботи? | ||
- Docker engine встановлений на хост з x86_64 | ||
- [Телеграм-бот](https://core.telegram.org/bots#6-botfather) та його токен (дивись [керівництво](https://core.telegram.org/bots/tutorial#obtain-your-bot-token)) | ||
- Chat ID чату, куди бот присиатиме повідомлення | ||
|
||
## Налаштування | ||
Просто надай `BOT_TOKEN` та `CHAT_ID` у файлі `.env`, можеш використовувати `.env.example` як приклад. Додатково можна обрати, щодо яких регіонів бот буде відправляти повідомлення, для цього використовуй змінну `REGION_LIST`, приклад і список регіонів, що підтримуються можеш знайти у `.env.example`. | ||
|
||
|
||
## Запуск | ||
### Збудуй власний імедж | ||
|
||
Клонуй цей репозиторій: | ||
|
||
```shell | ||
git https://github.com/yurnov/ua-explosion-notification-bot.git | ||
cd ua-explosion-notification-bot | ||
``` | ||
|
||
збудуй імедж | ||
|
||
```shell | ||
docker build . -t explosion-notification-bot | ||
``` | ||
|
||
Запускай | ||
|
||
```shell | ||
docker run --rm -d --env-file .env explosion-notification-bot | ||
``` | ||
|
||
Не забудь перед запуском відредагувати `.env` файл! | ||
|
||
### Запускай готовий імедж | ||
|
||
Відредагуй `.env` (дивись секцію налаштувань) та запускай уже збудований імедж: | ||
|
||
```shell | ||
docker pull ghcr.io/yurnov/explosion-notifier:latest | ||
docker run -d --rm --env-file .env ghcr.io/yurnov/explosion-notifier:latest | ||
``` | ||
|
||
Можеш використовувати теги `latest` для останньої випущеної версії, чи `dev` для версії, що розробляється. | ||
|
||
|
||
## Перестороги | ||
Це персональний проект, робота бота та актуальність даних не гарантуються. Не варто сприймати повідомлення для важливих для життя рішень! | ||
|
||
## Подяка | ||
Пану @v00g100skr та його [JAAM - Just another alerts map](https://github.com/J-A-A-M/ukraine_alarm_map) за ідею та сервер даних. | ||
|
||
Але головна подяка — ЗСУ!, можете і ви подякувати їм [тут](https://koloua.com/donate) | ||
|
||
## License | ||
Files included in this repository is avaliable under terms of [MIT license](LICENSE). external dependency, such as [requests](https://github.com/psf/requests) is avaliable under their own licenses. | ||
|
||
[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct-single.svg)](https://stand-with-ukraine.pp.ua) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
docker build . -f Dockerfile.black -t black | ||
docker run -it --rm -v $(pwd)/bot:/bot black | ||
docker run -it --rm -v $(pwd)/bot:/bot black pylint --disable=R,C,W1203,W0105 bot/main.py |
Oops, something went wrong.