Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Commit

Permalink
feat!: v3.0.0
Browse files Browse the repository at this point in the history
feat: add apprise notification service
feat: config gui generation (beta)
feat: group notifications
refactor: config
refactor: telegram dependencies
fix: smtp starttls
fix: explicit ConnectionError handling 
docs: reworked README.md add CONTRIBUTION.md
docs: added docstrings
test: add tests for everything
style: made code more pythonic
style: minimized flake8 and pylint warnings
  • Loading branch information
sibalzer committed Jun 7, 2021
2 parents 5d8e80b + 0e1fc9f commit 54cb3ff
Show file tree
Hide file tree
Showing 53 changed files with 2,342 additions and 546 deletions.
7 changes: 7 additions & 0 deletions .coveragerc
@@ -0,0 +1,7 @@
[run]
omit =
src/config_generator.py

[report]
exclude_lines =
if __name__ == .__main__.:
29 changes: 25 additions & 4 deletions .github/workflows/ci.yml
Expand Up @@ -3,7 +3,7 @@ name: ci
on: [push]

jobs:
build:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -14,11 +14,32 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install flake8 pylint pytest
pip install -r requirements.txt
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 src --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
flake8 src --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Lint with pylint
run: |
pylint src --fail-under 8
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Set up test env
run: |
pip install -e .
pip install coverage
- name: Generate Report
run: |
pip install coverage
coverage run -m pytest
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v1
8 changes: 5 additions & 3 deletions .github/workflows/release.yaml
@@ -1,11 +1,13 @@
name: release
on:
push:
branches:
- main
workflow_run:
workflows: ["ci"]
branch: [main]
types: [completed]
jobs:
build-tag-release:
name: Build, tag, and release Docker image
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down
9 changes: 8 additions & 1 deletion .gitignore
@@ -1,4 +1,11 @@
.vs
__pycache__
config.ini
*log
*log
.pytest_cache
*.egg-info
.vscode
build
dist
.coverage
htmlcov
4 changes: 4 additions & 0 deletions .pylintrc
@@ -0,0 +1,4 @@
[TYPECHECK]
generated-members=settings.Datastore.*
[LOGGING]
disable=logging-fstring-interpolation
19 changes: 7 additions & 12 deletions CHANGELOG.md
@@ -1,22 +1,22 @@
# Changelog

## [2.0.0](https://www.github.com/sibalzer/impfbot/compare/v1.2.1...v2.0.0) (2021-05-27)


### ⚠ BREAKING CHANGES

* Telegram Integration; Config Validation
* alert bug
* added Telegram integration
* Telegram Integration
* Config Validation

### Features

* added Telegram integration ([0540636](https://www.github.com/sibalzer/impfbot/commit/0540636f1e6b31a15ab28a438587615ffddbb33c))
* Telegram Integration; Config Validation ([874f26c](https://www.github.com/sibalzer/impfbot/commit/874f26ce5328bb44911864a8b108a764d2b4cf25))
* Telegram Integration ([0540636](https://www.github.com/sibalzer/impfbot/commit/0540636f1e6b31a15ab28a438587615ffddbb33c))
* Config Validation ([874f26c](https://www.github.com/sibalzer/impfbot/commit/874f26ce5328bb44911864a8b108a764d2b4cf25))


### Bug Fixes

* alert bug ([774e611](https://www.github.com/sibalzer/impfbot/commit/774e611bef1249a352d9cf3178c1810af5d3cced))
* alert bug ([47e2de0](https://www.github.com/sibalzer/impfbot/commit/47e2de0eb2f2e07b34e3c17cb7776ebaf98106cd))
* change output handler from stderr to stdout ([312852a](https://www.github.com/sibalzer/impfbot/commit/312852af0cdba8d3c97cf9985bd601945dd207aa))
* typo in README.md ([3e2c7a3](https://www.github.com/sibalzer/impfbot/commit/3e2c7a3af623ab2057d48fc0291549d76d253d1f))

Expand All @@ -32,19 +32,16 @@

### ⚠ BREAKING CHANGES

* alert bug

### Bug Fixes

* alert bug ([d5fd1ed](https://www.github.com/sibalzer/impfbot/commit/d5fd1ed2675683dd35cccce6868f3392d52c18df))
* alert bug ([b261e16](https://www.github.com/sibalzer/impfbot/commit/b261e16f49eae7a18dea8fa652a08c3bde2af5fa))

## [1.2.1](https://www.github.com/sibalzer/impfbot/compare/v1.2.1...v1.2.1) (2021-05-25)


### ⚠ BREAKING CHANGES

* added Telegram integration
* added Telegram Integration

### Features

Expand Down Expand Up @@ -77,7 +74,6 @@
### Bug Fixes

* email port ([556e16b](https://www.github.com/sibalzer/impfbot/commit/556e16b55a15d96a9082e29e390d074428193b82))
* mail port ([8178a46](https://www.github.com/sibalzer/impfbot/commit/8178a462c53f671874e5fa390a345367da98d460))

### [1.1.2](https://www.github.com/sibalzer/impfbot/compare/v1.1.1...v1.1.2) (2021-05-25)

Expand All @@ -91,7 +87,6 @@

### Bug Fixes

* config.ini.example ([871705b](https://www.github.com/sibalzer/impfbot/commit/871705b5054b91f85677ecd65730c5d8c0241e0d))
* email_list -> empfaenger ([80f4beb](https://www.github.com/sibalzer/impfbot/commit/80f4bebe794058ddd2bfa50a275a08f787f18e3f))

## [1.1.0](https://www.github.com/sibalzer/impfbot/compare/v1.0.0...v1.1.0) (2021-05-25)
Expand Down
27 changes: 27 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,27 @@
## Feature Requests

Eröffne ein [Issue](https://github.com/sibalzer/impfbot/issues/new/choose).

## Pull Request

Du möchtest mithelfen? Super! Gehe dazu wie folgt vor:

1. Eröffne ein Issue und/oder beantrage dich als Assignee
2. Nutze als Base Branch den Beta-Branch
3. Vervollständige benötigte Einstellungen unter `config-skeleton.py` (bei Sonderfällen muss evtl. der Parser `settings.py` bearbeitet werden) `config.ini.example`
4. Achte darauf, dass alle Test durchlaufen
5. Erstelle einen Pull Request & fertig

## Feature Requests

Open an [issue](https://github.com/sibalzer/impfbot/issues/new/choose).

## Pull Request

You want to help? Great! Proceed as follows:

1. open an issue and/or apply as assignee
2. use the beta branch as base branch
3. complete the needed settings in `config-skeleton.py` (in special cases you may have to edit the parser `settings.py`) `config.ini.example`.
4. make sure that all tests run through
5. create a pull request & thats it!
125 changes: 125 additions & 0 deletions README.en.md
@@ -0,0 +1,125 @@
# Notification bot for the Lower Saxony vaccination portal 🐴

![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/sibalzer/impfbot?label=version)
[![codecov](https://codecov.io/gh/sibalzer/impfbot/branch/main/graph/badge.svg?token=XXI3N5A9X1)](https://codecov.io/gh/sibalzer/impfbot)
[![Python](https://img.shields.io/badge/Made%20with-Python%203.x-blue.svg?style=flat&logo=Python&logoColor=white)](https://www.python.org/)
[![GitHub license](https://img.shields.io/github/license/sibalzer/impfbot)](https://github.com/sibalzer/impfbot/blob/main/LICENSE)

_Zur deutschen Version geht's [hier](https://github.com/sibalzer/impfbot/blob/main/README.md)._

A little weekend project of mine. The bot monitors the REST-API of the lower saxony vaccination portal (https://impfportal-niedersachsen.de) for free vaccination slots and sends a notification via mail. From then on, unfortunately, the fastest wins. Please do not abuse the bot and use moderate intervals.

## 🤖 Features

- Automatic search for short term vaccination dates
- Notifications via email and telegram & many more
- Opens your browser automatically when an appointment is found. All you have to do is enter your details!

> What the impfbot doesn't do: Book the appointment for you and/or enter your data automatically.
## ⚙️ Setup

### Requirements

- python 3.x via https://www.python.org/downloads/

### 📝 Instructions

Using Windows as an example:

1. download and install python from here: [https://www.python.org/downloads/](https://www.python.org/downloads/)
2. download the bot (Releases on the right side or [here](https://github.com/sibalzer/impfbot/releases/latest))
3. unpack the archive (the zip file)
4. rename `config.example.ini` to `config.ini` and fill in your data (zip code, birthday, email server data)
5. double-click on `windows_validate.bat` to check the config file
6. double-click on `windows_start.bat`

For advanced users, a docker container is also available as an alternative. See [docker](https://github.com/sibalzer/impfbot/tree/main/docker) for more information. Validating the config works via the command `docker exec impfbot python src/validate_config.py -a`.

### 📣 Setting up Telegram

1. write to https://t.me/BotFather and create bot. Then copy the token to `config.ini`.

The following steps must be performed for everyone who wants to receive messages.

2. write to https://t.me/userinfobot and copy "Id"-number into `config.ini` (separated with `,`)
3. ⚠ You have to start a conversation with your own bot before! (URL is in the Botfather message, press /start there). ⚠
4. validate that everything works: Double click on `test_telegram.bat`

### 🛠️ config.ini parameters

- **\[COMMON\]**: General settings
- `birthday` - Birthday to be queried. Example: `23.06.1912`.
- `group_size` - Size of the group for which an appointment is requested (2 to 15). Example: `5`
- `zip_code` - Five-digit zip code for your vaccination center. Example: `49123`
- **\[EMAIL\]**: Email settings
- `enable` - Specifies whether emails should be sent. `true` if yes, `false` otherwise.
- `sender` - The email address from which the notifications should be sent. Example: `sender@server.tld`.
- `user` - Login name for the SMTP server (in most cases identical with the sender address)
- `password` - The password for the SMTP server.
- `server` - The SMTP server. Example: `smtp.server.tld`.
- `port` - The port for the SMTP server. Example: `465`.
- `receivers` - A list of e-mail addresses to which a message should be sent. Example: `sender@server.tld,foo@server.tld,hoo@server.tld` or (only to itself) `sender@server.tld`.
- **\[TELEGRAM\]**: Telegram settings
- `enable` - Specifies whether Telegram messages should be sent. `true` if yes, otherwise `false`.
- `token` - The bot token from https://t.me/BotFather
- `chat_ids` - User-ID of the recipient: use https://t.me/userinfobot
- **\[WEBBROWSER\]**: Web browser settings
- `enable` - Determines if the browser should be opened automatically. (Only on desktop systems) `true` if yes, otherwise `false`.
- **\[APPRISE\]**: Various notification services (Pretty much anything you can think of).
- `enable` - `true` if Apprise should be used, otherwise `false`'.
- `service_uris` - Service-URIs. For more information please visit: [Apprise Documentation](https://github.com/caronc/apprise)
- **\[ADVANCED\]**: Settings for advanced users. It's gettting experimental 🤓
- `cooldown_between_requests` - wait time between requests. A too small wait time leads to an IP ban (default: 1min, but can be decreased empirically)
- `cooldown_between_failed_requests` - waiting time between failed attempts. For each additional one, the waiting time is added again to prevent an IP ban. I.e. five failures = waiting time of 5\*10s until the next request.
- `cooldown_after_ip_ban` - If a query fails 10 times the IP is probably banned. By default it will wait for 3h.
- `cooldown_after_success` - Cooldown after an vaccination slot was found. By default it will wait 15min.
- `jitter` - random time span from 0-jtter seconds which is added to the wait times (default: `5`)
- `sleep_at_night` - Specifies if the bot should sleep at night (default: `true` since no events are published anyway)
- `user_agent`- The user agent is passed in the header (default: `impfbot`)

##### Example Config:

```ini
[COMMON]
zip_code=42042
birthdate=23.06.1912

[EMAIL]
enable=true
sender=sender@server.de
user=username
password=xxxxxx
server=smtp.server.de
port=465
receivers=sender@server.de,guenni@server.de,frida@server.de

[TELEGRAM]
enable=true
token=TOKEN
chat_ids=123456789,987654321

[WEBBROWSER]
enable=true

[APPRISE]
enable=false
service_uris=discord://webhook_id/webhook_token,matrix://hostname

[ADVANCED]
cooldown_between_requests=60
cooldown_between_failed_requests=10
cooldown_after_ip_ban=10800
cooldown_after_success=900
jitter=5
sleep_at_night=true
user_agent=impfbot
```

## ⭐ Sponsorship

The impfbot helped you and you want to contribute monetarily? Then donate at [this fundraiser to Doctors Without Borders](https://www.aerzte-ohne-grenzen.de/spenden-sammeln?cfd=z1suz). (Yes, somewhat cribbed from [vaccipy](https://github.com/iamnotturner/vaccipy). But I liked the idea.)

## 🙏 Many thanks to:

- [paulypeter](https://github.com/paulypeter) - Telegram Integration & more

0 comments on commit 54cb3ff

Please sign in to comment.