Skip to main content

Python Wrapper for IFTTT Webhook interaction.

Project description

This package provides a simple interface to interact with If This Then That (https://ifttt.com/) webhook events.

This project was born from the need to receive push notifications on a smartphone after long running jobs had finished running, particularly using a free service such as IFTTT.

Copyright ® 2019, Ruben Branco <ruben.branco@outlook.pt>. All rights reserved.

Links: https://github.com/RubenBranco/pyifttt | https://pypi.org/project/pyifttt/

Installation

Install pyifttt using pip:

pip3 install pyifttt

Usage

There are three essential items to interact with a webhook:

  1. Event Name: The event name for the webhook defined in the website.

  2. Key: Your personal ifttt maker key.

  3. Data: The values of each declared form variables.

General Usage

from pyifttt.webhook import send_notification

data = dict(value1="Testing this event")
key = "MySuperPrivateKey"

send_notification("test_event", data, key)

This will send a notification to an webhook whose event is named test_event with value1 variable as “Testing this event” and with a key.

Since including a private key in script files can be bothersome and repetitive, ifttt has three ways of key input:

  1. Through the function as a key kwarg.

  2. As a system env variable named IFTTT_KEY (export IFTTT_KEY="MySuperPrivateKey).

  3. As a home file (~/.ifttt). The only contents this file should have is the key.

Job Completion Notification

pyifttt implements a general notification system for push notification of program exits.

In your IFTTT webhook you should include the following message:

The program {{Value1}}, running on host machine {{Value2}} , finished at {{OccurredAt}}. {{Value3}}

Here’s how you would use pyifttt to receive push notifications for when your long running program finishes using a context manager:

from pyifttt.webhook import SendCompletionNotification

with SendCompletionNotification('test_event'):
    execute_long_job()

This will send a push notification to your smartphone or other device with the following structure:

The program long_job.py, running on host machine Server1, finished at November 22, 2019 at 09:30PM.

If it had found an exception, it would show the following message:

The program long_job.py, running on host machine Server1, finished at November 22, 2019 at 09:30PM. Got exception KeyboardInterrupt.

An optional argument to SendCompletionNotification is the IFTTT key, which as previously described, has several ways of input.

If you prefer to not use it as a context manager, you also use it in the following way:

from pyifttt.webhook import send_completion_notification

execute_long_job()
send_completion_notification('test_event')

License

Distributed under GPL-3.0 License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyifttt-0.1.4.tar.gz (3.6 kB view details)

Uploaded Source

File details

Details for the file pyifttt-0.1.4.tar.gz.

File metadata

  • Download URL: pyifttt-0.1.4.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.4

File hashes

Hashes for pyifttt-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f0f4154ffe5b9c096971c43342e9858f3ad0c4f434e75cc3466495fd591141e1
MD5 1cd341d6c729fa23bdbd7ba3d9db04b0
BLAKE2b-256 3e98eac33c1f43e237a3aee45bbf530c497594537fbb153d37628c14dd126251

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page