Python script notifying if an item becomes available in your favourites on TooGoodToGo
It works by fetching the available favourites from TooGoodToGo, checking against saved items in list.json
if they have been sent a notification, if not it will send them according to your notification method. Finally, it saves the new available favourites in list.json
for the next run
Works with at most 400 favourites (API limit)
This script should be ran using a task scheduler (such as cron) to check availability periodically using this command:
python3 tgtg-notifier.py
- Python 3
- tgtg (TooGoodToGo API)
- pytz (to handle timezones)
- currency-symbols (to display currency correctly)
Using the tgtg package, you can retrieve your user_id
and an access_token
(more info on tgtg's pypi page) using:
client = TgtgClient(email="YOUR EMAIL ADDRESS", password="YOUR PASSWORD")
client._login()
print("user_id: " + client.user_id)
print("access_token: " + client.access_token)
You can then write them in the beginning of the script here:
# https://pypi.org/project/tgtg/
client = TgtgClient(
access_token="",
user_id=""
)
In this part of the code you can add your custom notification method instead of the print()
statements. It's up to you to choose how you wish to be notified (by email, with a push notification, etc...)
############################################################################
# ADD NOTIFICATION COMMANDS HERE (SEND EMAIL, SEND PUSH NOTIFICATION, ...) #
############################################################################
print(item["display_name"] + " | TooGoodToGo")
print("From " + start + " to " + end + " - " + price)