Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
[Share] IFTTT and Pythonista - Webhooks
-
I thought I would share this. I did not know about the Webhooks trigger in IFTTT before. So if you are interested in IFTTT, there is a trigger applet called Webhooks. You need to get an API key to use it, but if you already have an account its very easy. Just google search it.
Anyway, the Webhook responds to a post with a URL containing a api key, event name and 3 optional values. (As far as I know, I have just started playing with it).
So with requests it pretty simple to create the URL and do a post that triggers a WebHook which I turn calls an action applet. It's super basic and maybe of limited interest. But I think its pretty nice for how easy it is to use.
the code below, I copied from this repo and just added a way to get my API Key from the keychain module.
I just left it as a simple example. The code below will not work for anyone. You need to get you API Key as well as create WebHook. I included a pic of the WebHook config. If you are used to IFTTT, this is really simple. Even if you are not used to IFTTT, does not take long to get the hang out it. Btw IFTTT = (IF This, Then That). So if This trigger then do that action.Ok, again this is quite basic, at least on the surface. But for example, you want to control your Phillips Hue lights, you can. Not to the same degree if you where using a Python Module for Phillips hue (I think there is one called phue). In my simple example, I am just sending myself a iOS nofitication which is pretty boring considering Pythonista has the notification module built it. But I was just trying to crawl before running.
Anyway, I hope someone finds this useful. I think I will as I look deeper into it. I have a lot of IOT gadgets, but for the most part they are the triggers not the actions.
# -*- coding: utf-8 -*- """Handle sending API requests to the IFTTT Webhooks Channel""" import keychain import requests # get my secret API password from keychain _api_key = keychain.get_password('IFTTT', 'WebHooks') _event = 'xxx' def send_event(api_key, event, value1=None, value2=None, value3=None): """Send an event to the IFTTT maker channel Parameters: ----------- api_key : string Your IFTTT API key event : string The name of the IFTTT event to trigger value1 : Optional: Extra data sent with the event (default: None) value2 : Optional: Extra data sent with the event (default: None) value3 : Optional: Extra data sent with the event (default: None) """ url = 'https://maker.ifttt.com/trigger/{e}/with/key/{k}/'.format(e=event, k=api_key) payload = {'value1': value1, 'value2': value2, 'value3': value3} return requests.post(url, data=payload) if __name__ == '__main__': x = send_event(_api_key, _event) print(x)