Skip to content

Commit

Permalink
Merge pull request #277 from Der-Henning/dev
Browse files Browse the repository at this point in the history
bump version 1.15.0
  • Loading branch information
Der-Henning authored Feb 13, 2023
2 parents 7a54b61 + 6e1601c commit de0bbb4
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 93 deletions.
20 changes: 12 additions & 8 deletions DOCKER_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Readme, source and documentation on [https://github.com/Der-Henning/tgtg](https:

- [`edge`](https://github.com/Der-Henning/tgtg/blob/main/Dockerfile)
- [`edge-alpine`](https://github.com/Der-Henning/tgtg/blob/main/Dockerfile.alpine)
- [`v1`, `v1.14`, `v1.14.10`, `latest`](https://github.com/Der-Henning/tgtg/blob/v1.14.10/Dockerfile)
- [`v1-alpine`, `v1.14-alpine`, `v1.14.10-alpine`, `latest-alpine`](https://github.com/Der-Henning/tgtg/blob/v1.14.10/Dockerfile.alpine)
- [`v1`, `v1.15`, `v1.15.0`, `latest`](https://github.com/Der-Henning/tgtg/blob/v1.15.0/Dockerfile)
- [`v1-alpine`, `v1.15-alpine`, `v1.15.0-alpine`, `latest-alpine`](https://github.com/Der-Henning/tgtg/blob/v1.15.0/Dockerfile.alpine)

# Quick Start

Expand All @@ -28,13 +28,15 @@ services:
- DEBUG=false
- TGTG_USERNAME=
- SLEEP_TIME=60
- SCHEDULE_CRON=
- ITEM_IDS=
#- SCHEDULE_CRON=
#- ITEM_IDS=
- METRICS=false
- METRICS_PORT=8000
- DISABLE_TESTS=false
- QUIET=false
- LOCALE=en_US

- SMTP=true
- SMTP=false
- SMTP_HOST=smtp.gmail.com
- SMTP_PORT=465
- [email protected]
Expand All @@ -52,7 +54,7 @@ services:
- TELEGRAM=false
- TELEGRAM_TOKEN=
- TELEGRAM_CHAT_IDS=
- TELEGRAM_TIMEOUT=60
#- TELEGRAM_TIMEOUT=60
#- TELEGRAM_BODY=

- IFTTT=false
Expand All @@ -63,8 +65,10 @@ services:
- WEBHOOK_URL=
- WEBHOOK_METHOD=POST
- WEBHOOK_BODY=
- WEBHOOK_TYPE=
- WEBHOOK_TIMEOUT=60
- WEBHOOK_TYPE=plain/text
#- WEBHOOK_HEADERS=
#- WEBHOOK_TIMEOUT=60
#- WEBHOOK_CRON=
volumes:
- tokens:/tokens

Expand Down
122 changes: 68 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,63 +15,100 @@ This software is provided as is without warranty of any kind. If you have proble

## Disclaimer

Too Good To Go explicitly forbids the use of their platform the way this tool does. In their Terms and Conditions it says: "The Consumer must not misuse the Platform (including hacking or 'scraping')."
This Project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with Too Good To Go, or any of its subsidiaries or its affiliates.

If you use this tool you do it at your own risk. TGTG may stop you from doing so by (temporarily) blocking your access and may even delete your account.
Too Good To Go explicitly forbids the usege of their platform the way this tool does if you use it. In their Terms and Conditions it says: "The Consumer must not misuse the Platform (including hacking or 'scraping')."

If you use this tool you do it at your own risk. Too Good To Go may stop you from doing so by (temporarily) blocking your access and may even delete your account.

## Error 403

If you see the Error 403 in your logs please refer to the [FAQ](https://github.com/Der-Henning/tgtg/wiki/FAQ#1-i-am-getting-error-403-all-the-time).

## Installation

You can install this tool on any computer. For 24/7 notifications I recommended to install the tool on a NAS like Synology or a Raspberry Pi. You can also use a virtual cloud server. Starting at 1,00 €/Month at Strato.de or try AWS free tier.
You can install this tool on any computer. For 24/7 notifications I recommended to an installation on a NAS like Synology or a Raspberry Pi. You can also try to use a virtual cloud server.

If you have any problems or questions feel free to create an issue.

For configuration options see [`config.sample.ini`](https://github.com/Der-Henning/tgtg/blob/main/src/config.sample.ini) or [`docker-compose.yml`](https://github.com/Der-Henning/tgtg/blob/main/docker-compose.yml).

You have the following three options to install the scanner, ascending in complexity:

### Use prebuild Release

This is the simplest but least flexible solution suitable for most operating systems.

The binaries are build for Linux, MacOS and Windows running on a `x64` architecture. If you are using an other architecture like `arm` (e.g. Raspberry Pi) you have to run from source, compile the binary yourself or use the docker images.

1. Download latest [Releases](https://github.com/Der-Henning/tgtg/releases) for your OS
2. Unzip the archive
3. Edit ```config.ini``` as described in the file
3. Edit `config.ini` as described in the file
4. Run scanner

You can run the scanner manually if you need it, add it to your system startup or create a service.
You can run the scanner manually if you need it, add it to your startup or create a system service.

The executables for Windows and MacOS are not signed by Microsoft and Apple, which would be very expensive.
On Mac you need to hold the control key while opening the file and on Windows you need to confirm the displayed dialog.

### Run with Docker

My preferred method for servers using the pre build multi-arch linux images available on [Docker Hub](https://hub.docker.com/r/derhenning/tgtg).
My preferred method for servers, NAS and RapsberryPis is using the pre build multi-arch linux images available via [Docker Hub](https://hub.docker.com/r/derhenning/tgtg). The images are build for linux on `amd64`, `arm64`, `armv7`, `armv6` and `i386`.

1. Install Docker and docker-compose
2. Copy and edit ```docker-compose.yml``` as described in the file
3. Run ```docker-compose up -d```
2. Copy and edit `docker-compose.yml` as described in the file
3. Run `docker-compose up -d`

The container creates a volume mounting ```\tokens``` where the app saves the TGTG credentials after login. These credentials will be reused on every start of the container to avoid the mail login process. To login with a different account you have to delete the created volume.
The container automatically creates a volume mounting `\tokens` where the app saves the TGTG credentials after login. These credentials will be reused on every start of the container to avoid the mail login process. To login with a different account you have to delete the created volume or the files in it.

### Run from source

Method for developers.
Method for advanced usage.

1. Install Python>=3.9 and pip
2. Run `pip install -r requirements.txt`
3. Create `src/config.ini` as described in the file `config.template.ini`
4. Run `python src/main.py`

Alternatively you can use environment variables as described in the `sample.env` file. The scanner will look for environment variables if no `config.ini` is present.

### Build your own binary

You could also build your own binary for your OS/Arch combination.

1. Install Python>=3.9 and pip
2. Run ```pip install -r requirements.txt```
3. Create ```src/config.ini``` as described in the file ```config.template.ini```
4. Run ```python src/main.py```
2. Run `pip install -r requirements-build.txt`
3. Run `make executable` or `pyinstaller scanner.spec`

Alternatively you can use environment variables as described in the ```sample.env``` file. The scanner will look for environment variables if no ```config.ini``` is present.
You will find the bundled binary including the `config.ini` in the `./dist` directory.

### Running
## Usage

When the scanner is started it will first try to login to your TGTG account. Similar to logging in to the TGTG app, you have to click on the link send to you by mail. This won't work on your mobile phone if you have installed the TGTG app, so you have to check your mailbox on PC.

After a successful login the scanner will send a test notification on all configured notifiers. If you don't receive any notifications, please check your configuration.

### Helper functions

The executable or the `src/main.py` contains some useful helper functions that can be accessed via optional command line arguments. Running `scanner(.exe) --help` or `python src/main.py --help` displays the available commands.

````
usage: main.py [-h] [-v] [-d] [-t] [-f] [-F] [-a item_id [item_id ...]] [-r item_id [item_id ...]] [-R]
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-d, --debug activate debugging mode
-t, --tokens display your current access tokens and exit
-f, --favorites display your favorites and exit
-F, --favorite_ids display the item ids of your favorites and exit
-a item_id [item_id ...], --add item_id [item_id ...]
add item ids to favorites and exit
-r item_id [item_id ...], --remove item_id [item_id ...]
remove item ids from favorites and exit
-R, --remove_all remove all favorites and exit
````

### Metrics

Enabling the metrics option will expose a http server on the specified port supplying the currently available items. You can scrape the data with prometheus to create and visualize historic data or use it with your home automation.
Expand All @@ -88,54 +125,31 @@ Scrape config:
- 'localhost:8000'
````

## Developing
## Developement

For development I recommend using docker. The Makefile depends on docker and docker-compose.
For development I recommend using docker.

Create ```.env``` based on ```sample.env``` for configuration.
If you are developing with VSCode, you can open the project in the configured development container.

Developing with VSCode you can open the project in the configured development container.

### Makefile commands

```make image``` builds docker image with tag ```tgtg-scanner:latest```

```make install``` installs dependencies

```make start``` short for ```python src/main.py```

```make bash``` starts dev python docker image with installed dependencies and mounted project in bash

```make executable``` creates bundled executable in ```/dist```

```make test``` runs unit tests

```make clean``` cleans up docker compose

### Helper functions

```src/main.py``` contains some useful helper functions that can be accessed via optional command line arguments. Running ```python src/main.py --help``` displays the available commands.
To install all required dependencies for the developement environment, including linting, testing and building, run

````bash
pip install -r requirements-dev.txt
````
usage: main.py [-h] [-v] [-d] [-t] [-f] [-F] [-a item_id [item_id ...]] [-r item_id [item_id ...]] [-R]

optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-d, --debug activate debugging mode
-t, --tokens display your current access tokens and exit
-f, --favorites display your favorites and exit
-F, --favorite_ids display the item ids of your favorites and exit
-a item_id [item_id ...], --add item_id [item_id ...]
add item ids to favorites and exit
-r item_id [item_id ...], --remove item_id [item_id ...]
remove item ids from favorites and exit
-R, --remove_all remove all favorites and exit
````
### Makefile commands

- `make image` builds docker image with tag `tgtg-scanner:latest`
- `make install` installs dependencies
- `make start` short for `python src/main.py`
- `make bash` starts dev python docker image with installed dependencies and mounted project in bash
- `make executable` creates bundled executable in `/dist`
- `make test` runs unit tests
- `make clean` cleans up docker compose

### Creating new notifiers

Feel free to create and contribute new notifiers for other services and endpoints. You can use an existing notifier as template.
Feel free to create and contribute new notifiers for other services and endpoints. You can use an existing notifier as template or build upon the webhook notifier. E.g. see the [ifttt notifier](https://github.com/Der-Henning/tgtg/blob/main/src/notifiers/ifttt.py).

---
If you want to support me, feel free to buy me a coffee.
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ services:
context: .
dockerfile: Dockerfile.dev
working_dir: /home/app
env_file:
- .env
# env_file:
# - .env
volumes:
- .:/home/app
stdin_open: true
Expand Down
12 changes: 9 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ services:
- METRICS=false ## Enable to export metrics for Prometheus
- METRICS_PORT=8000 ## Port for metrics http server
- DISABLE_TESTS=false ## true to disable test notifications on startup
- quiet=false ## true to disable all console messages. Only errors and console notifier messages
- QUIET=false ## true to disable all console messages. Only errors and console notifier messages
- LOCALE=en_US ## set locale to localize ${{pickupdate}}

- CONSOLE=false ## true = enable simple console notifications
#- CONSOLE_BODY= ## console message with variables as described below
Expand All @@ -33,18 +34,21 @@ services:
- SMTP_SSL=false ## enable SSL
- [email protected] ## sender adress - same as Login for google and most smtp servers
- [email protected] ## recipient for notifications - can be the same as sender
#-SMTP_SUBJECT= ## Subject and Body options are optional.
#-SMTP_BODY= ## Subject and Body options can use variables as described below
#- SMTP_CRON=
#- SMTP_SUBJECT= ## Subject and Body options are optional.
#- SMTP_BODY= ## Subject and Body options can use variables as described below
## The Body option is interpreted as HTML

- PUSH_SAFER=false ## true = enable notifications via pushsafer.com
- PUSH_SAFER_KEY=
- PUSH_SAFER_DEVICE_ID=
#- PUSH_SAFER_CRON=

- TELEGRAM=false ## true = enable notifications via Telegram
- TELEGRAM_TOKEN= ## Telegram Bot token - see @botfather
- TELEGRAM_CHAT_IDS= ## Telegram Chat id, multiple ids separated by comma
- TELEGRAM_TIMEOUT=60 ## Timeout for Telegram API requests
#- TELEGRAM_CRON=
#- TELEGRAM_BODY= ## Optional message body as markdown, variables as described below
## Example:
## 'TELEGRAM_BODY=*$${{display_name}}*\n*Available*: $${{items_available}}\n*Rating*: $${{rating}}\n*Price*: $${{price}} $${{currency}}\n*Pickup*: $${{pickupdate}}'
Expand All @@ -54,6 +58,7 @@ services:
- IFTTT=false ## true = enable notifications via IFTTT Webhooks
- IFTTT_EVENT=tgtg_notification ## IFTTT Webhooks Event
- IFTTT_KEY= ## IFTTT Webhooks Key
#- IFTTT_CRON=
- IFTTT_BODY= ## IFTTT json data body
## Default: {"value1": "$${{display_name}}", "value2": $${{items_available}}, "value3": "https://share.toogoodtogo.com/item/$${{item_id}}"}

Expand All @@ -69,6 +74,7 @@ services:
- WEBHOOK_TYPE=application/json ## Content-Type for header, default: text/plain
- WEBHOOK_HEADERS={} ## Additional headers
- WEBHOOK_TIMEOUT=60 ## Request Timeout
#- WEBHOOK_CRON=
volumes:
- tokens:/tokens ## volume to save TGTG credentials to reuse on next start up and avoid login mail
volumes:
Expand Down
11 changes: 11 additions & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ ITEM_IDS=
METRICS=false
METRICS_PORT=8000
DISABLE_TESTS=false
QUIET=false
LOCALE=en_US

TGTG_USERNAME=
TGTG_ACCESS_TOKEN=
TGTG_REFRESH_TOKEN=
TGTG_USER_ID=
TGTG_DATADOME=

CONSOLE=false
CONSOLE_BODY=
CONSOLE_CRON=

SMTP=false
SMTP_HOST=smtp.gmail.com
Expand All @@ -22,25 +28,30 @@ SMTP_TLS=true
SMTP_SSL=false
SMTP_SENDER=
SMTP_RECIPIENT=
SMTP_CRON=

PUSH_SAFER=false
PUSH_SAFER_KEY=
PUSH_SAFER_DEVICE_ID=
PUSH_SAFER_CRON=

IFTTT=false
IFTTT_EVENT=tgtg_notification
IFTTT_BODY=
IFTTT_KEY=
IFTTT_CRON=

TELEGRAM=false
TELEGRAM_TOKEN=
TELEGRAM_CHAT_IDS=
TELEGRAM_TIMEOUT=60
TELEGRAM_BODY=
TELEGRAM_CRON=

WEBHOOK=false
WEBHOOK_URL=
WEBHOOK_METHOD=POST
WEBHOOK_BODY=
WEBHOOK_TYPE=
WEBHOOK_TIMEOUT=60
WEBHOOK_CRON=
2 changes: 1 addition & 1 deletion src/_version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__title__ = "TGTG Scanner"
__description__ = "Provides notifications for TGTG magic bags"
__version__ = "1.14.10"
__version__ = "1.15.0"
__author__ = "Henning Merklinger"
__author_email__ = "[email protected]"
__license__ = "GPL"
Expand Down
Loading

0 comments on commit de0bbb4

Please sign in to comment.