Python module

This is an example of a Python module that you can save and use in your scripts to trigger notifications when needed.

Usage:

Example
from notify17 import n17_raw, n17_template

n17_raw("RAW_API_KEY", 'Oh, a title!', 'And a content!')
n17_template('TEMPLATE_API_KEY', {'name': 'Mr. Anderson'})

Module:

notify17.py
# Notify17 helper functions

import urllib.request
import json


def n17_template(template_api_key: str, data: dict):
    """
    Triggers a Notify17 notification using a notification template.

    :param template_api_key: Notification template API key
    :param data: Payload to pass to the template
    """
    req = urllib.request.Request("https://hook.notify17.net/api/template/" + template_api_key)
    req.add_header('Content-Type', 'application/json; charset=utf-8')
    json_data = json.dumps(data)
    json_data_bytes = json_data.encode('utf-8')
    req.add_header('Content-Length', len(json_data_bytes))
    urllib.request.urlopen(req, json_data_bytes)


def n17_raw(raw_api_key: str, title: str, content: str = ''):
    """
    Triggers a Notify17 notification using a Raw API key.

    :param raw_api_key: Raw API key
    :param title: Title of the notification (required)
    :param content: Content of the notification
    """
    req = urllib.request.Request("https://hook.notify17.net/api/raw/" + raw_api_key)
    req.add_header('Content-Type', 'application/json; charset=utf-8')
    json_data = json.dumps({'title': title, 'content': content})
    json_data_bytes = json_data.encode('utf-8')
    req.add_header('Content-Length', len(json_data_bytes))
    urllib.request.urlopen(req, json_data_bytes)

Usage:

Example
from notify17 import n17_raw, n17_template

n17_raw("RAW_API_KEY", 'Oh, a title!', 'And a content!')
n17_template('TEMPLATE_API_KEY', {'name': 'Mr. Anderson'})