Conversation
Notification plugin to send notification to ifttt.com's webhook service. (https://ifttt.com/maker_webhooks)
flexget/plugins/notifiers/ifttt.py
Outdated
| :param str title: message subject | ||
| :param dict config: plugin config | ||
| """ | ||
| notification_body = dict() |
There was a problem hiding this comment.
Just declare the dict with the data directly
| notification_body = dict() | ||
| notification_body['value1'] = title | ||
| notification_body['value2'] = message | ||
| for key in config['keys']: |
There was a problem hiding this comment.
This won't work if keys is a string. You need to make sure it's a list. Look into other notifiers with prepare_data methods
flexget/plugins/notifiers/ifttt.py
Outdated
| for key in config['keys']: | ||
| url = self.url_template.format(config['event'], key) | ||
| try: | ||
| res = self.session.post(url, json = notification_body) |
There was a problem hiding this comment.
Remove spaces around key word calls.
Also, using Session() will raise on errors by default, so you'll never reach that else clause. Just remove the conditionals and assume that the notification was successful. Handle the failure in the except section
flexget/plugins/notifiers/ifttt.py
Outdated
| else: | ||
| log.error("Error sending to: {}: {} {} -- {}".format(url, res.status_code, res.reason, res.text)) | ||
| except HTTPError as e: | ||
| log.error("Error sending to {}: {}".format(url, e)) |
There was a problem hiding this comment.
Please raise plugin.PluginWarning here. Look into other notifiers
flexget/plugins/notifiers/ifttt.py
Outdated
| log.info("Sent notification to key: {}".format(key)) | ||
| else: | ||
| log.error("Error sending to: {}: {} {} -- {}".format(url, res.status_code, res.reason, res.text)) | ||
| except HTTPError as e: |
There was a problem hiding this comment.
I think it's better to catch all RequestError here, just in case
flexget/plugins/notifiers/ifttt.py
Outdated
| raise PluginWarning("Failed to send notifications") | ||
|
|
||
| def prepare_config(self, config): | ||
| if isinstance(config['keys'], StringTypes): |
There was a problem hiding this comment.
if not isinstance(config['keys'], list):
I don't think we've ever used StringTypes. Either use str or the example I made.
There was a problem hiding this comment.
list it is then :)
I am not a big fan of str with all the unicode hassle, that is why I usually resort to StringTypes. And testing for a list has other caveats (they end up being tuples sometimes for eg) but if it is more consistent with the rest of your code base, then sure. jsonschema makes it moot anyway most probably here.
|
@liiight Fixed it up based on your comments, thanks. Few questions:
Also, while I was scratching my own itch I realized that you actually have a feature request for this: https://feathub.com/Flexget/Flexget/+19 |
flexget/plugins/notifiers/ifttt.py
Outdated
| url = self.url_template.format(config['event'], key) | ||
| try: | ||
| self.session.post(url, json=notification_body) | ||
| log.info("Sent notification to key: {}".format(key)) |
There was a problem hiding this comment.
let the logger handle its own interpolation:
log.info("Sent notification to key: %s", key)
Notification plugin to send notification to ifttt.com's webhook service.
(https://ifttt.com/maker_webhooks)
Motivation for changes:
Adds a simple notification plugin to send the notification to IFTTT webhook trigger that then can be used
in an IFTTT applet.
Config usage if relevant (new plugin or updated schema):
Log and/or tests output (preferably both):