Der-Henning / tgtg

Scanner for Too Good To Go Notifications
https://github.com/Der-Henning/tgtg/wiki
GNU General Public License v3.0
410 stars 66 forks source link

Add shell script notifier #334

Closed sjoerdj closed 1 year ago

sjoerdj commented 1 year ago

Thanks for this great tool!

Would it be possible to add a shell script notifier that for example could kick off notification via e.g. Yowsup?

[SCRIPT] enabled = true script_file = yowsup_notify.sh

I imagine that the yowsup_notify.sh then could look as follows:

#!/bin/bash

# yowsup settings TempFileDir="/tmp/" WhatsappPath="/usr/local/bin/" WhatsappHomePath="/root/.config/yowsup/" WhatsappConfigFile=$WhatsappHomePath"491612345678/config.json" WhatsappRecipient1=491712345678

# send WhatsApp message yowsup-cli demos -c $WhatsappConfigFile -s $WhatsappRecipient1 "${display_name}\n${currency} ${price}\n${items_available} bags available"

Such a script notifier would allow for working with scanner data in a very flexible way, I'd think.

Der-Henning commented 1 year ago

Hi @sjoerdj. That's a nice idea indeed. But as I am very busy at the moment, it may take some time until I have the resources to elaborate and implement this feature. Wouldn't you like to try to implement it yourself and contribute to the project? I would be happy to review your code and support you if you have any issues.

sjoerdj commented 1 year ago

Hi @Der-Henning,

Thanks for your message. I am a newbie to programming, but I managed to complete the script file:

#!/bin/bash ` # yowsup settings TempFileDir="/tmp/" WhatsappPath="/usr/local/bin/" WhatsappHomePath="/root/.config/yowsup/" WhatsappConfigFile=$WhatsappHomePath"491612345678/config.json" WhatsappRecipient1=491712345678 # obtain data from command line while getopts n:a: option do case "${option}" in n) display_name=${OPTARG};; a) items_available=${OPTARG};; esac done # build WhatsApp message read -r -d '' WhatsappMessage << EOM ${display_name} ${items_available} bag(s) available EOM # send WhatsApp message yowsup-cli demos -c $WhatsappConfigFile -s $WhatsappRecipient1 "$WhatsappMessage"`

As you can see, my idea is to pass the data via command options and arguments as soon as a scanned bag becomes available:

[SCRIPT] enabled = true command = bash whatsapp_notify.sh -n "${{display_name}}" -a ${{items_available}}

I gave the related coding in tgtg a try: sample.env src/config.sample.ini src/notifiers/notifiers.py scr/notifiers/script.py scr/models/errors.py

Der-Henning commented 1 year ago

Looks good. Feel free to create a pull request and I will review your code. Mark the PR as draft as long you are not ready to merge. And please use the dev branch as base branch for your PR. Thank you.

sjoerdj commented 1 year ago

You're welcome! Pull request done.