pax_global_header00006660000000000000000000000064131357126040014514gustar00rootroot0000000000000052 comment=fed3d8ec87811cf33c87d9d102845a420204577b briandconnelly-pyfttt-926f71a/000077500000000000000000000000001313571260400164105ustar00rootroot00000000000000briandconnelly-pyfttt-926f71a/.gitignore000066400000000000000000000012761313571260400204060ustar00rootroot00000000000000# Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] # C extensions *.so # Distribution / packaging .Python env/ build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ *.egg-info/ .installed.cfg *.egg # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *,cover # Translations *.mo *.pot # Django stuff: *.log # Sphinx documentation docs/_build/ # PyBuilder target/ briandconnelly-pyfttt-926f71a/LICENSE000066400000000000000000000024221313571260400174150ustar00rootroot00000000000000Copyright (c) 2015, Brian Connelly All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. briandconnelly-pyfttt-926f71a/MANIFEST.in000066400000000000000000000000361313571260400201450ustar00rootroot00000000000000include *.rst include LICENSE briandconnelly-pyfttt-926f71a/README.rst000066400000000000000000000025311313571260400201000ustar00rootroot00000000000000pyfttt ====== Python tools for interacting with IFTTT Webhooks Channel. Installation ------------ :: pip install pyfttt Command Line Tool ----------------- ``pyfttt`` is an included command line tool for sending Webhooks Channel events. To see a list of available arguments, run ``pyfttt --help``, which produces: :: usage: pyfttt [-h] [--version] [-k K] -e E [value1] [value2] [value3] Send Webhooks Channel events to IFTTT optional arguments: -h, --help show this help message and exit --version show program's version number and exit sending events: -k K, --key K IFTTT secret key -e E, --event E The name of the event to trigger value1 Extra data sent with the event (optional) value2 Extra data sent with the event (optional) value3 Extra data sent with the event (optional) Visit https://ifttt.com/channels/maker_webhooks for more information The ``--key`` argument can be omittrd if the IFTTT secret key is defined in the environment as ``IFTTT_API_KEY``. Requirements ------------ - Python 2.7 or greater - `requests `__ License ------- pyfttt is released under the BSD 2-clause license. See `LICENSE `__ for details. briandconnelly-pyfttt-926f71a/pyfttt/000077500000000000000000000000001313571260400177425ustar00rootroot00000000000000briandconnelly-pyfttt-926f71a/pyfttt/__init__.py000066400000000000000000000002451313571260400220540ustar00rootroot00000000000000# -*- coding: utf-8 -*- VERSION = (0, 3, 2) __version__ = ".".join(map(str, VERSION[0:3])) + "".join(VERSION[3:]) __license__ = "BSD" from pyfttt.sending import * briandconnelly-pyfttt-926f71a/pyfttt/cmd_script.py000066400000000000000000000051131313571260400224430ustar00rootroot00000000000000# -*- coding: utf-8 -*- """pyfttt.py - Send IFTTT Webhooks Channel Events""" import argparse import os import sys import requests import pyfttt def parse_arguments(): """Parse command line arguments""" parser = argparse.ArgumentParser(prog=sys.argv[0], description='Send Webhooks Channel events to IFTTT', epilog='Visit https://ifttt.com/channels/maker_webhooks for more information') parser.add_argument('--version', action='version', version=pyfttt.__version__) sgroup = parser.add_argument_group(title='sending events') sgroup.add_argument('-k', '--key', metavar='K', default=os.environ.get('IFTTT_API_KEY'), help='IFTTT secret key') sgroup.add_argument('-e', '--event', metavar='E', required=True, help='The name of the event to trigger') sgroup.add_argument('value1', nargs='?', help='Extra data sent with the event (optional)') sgroup.add_argument('value2', nargs='?', help='Extra data sent with the event (optional)') sgroup.add_argument('value3', nargs='?', help='Extra data sent with the event (optional)') return parser.parse_args() def main(): """Main function for pyfttt command line tool""" args = parse_arguments() if args.key is None: print("Error: Must provide IFTTT secret key.") sys.exit(1) try: res = pyfttt.send_event(api_key=args.key, event=args.event, value1=args.value1, value2=args.value2, value3=args.value3) except requests.exceptions.ConnectionError: print("Error: Could not connect to IFTTT") sys.exit(2) except requests.exceptions.HTTPError: print("Error: Received invalid response") sys.exit(3) except requests.exceptions.Timeout: print("Error: Request timed out") sys.exit(4) except requests.exceptions.TooManyRedirects: print("Error: Too many redirects") sys.exit(5) except requests.exceptions.RequestException as reqe: print("Error: {e}".format(e=reqe)) sys.exit(6) if res.status_code != requests.codes.ok: try: j = res.json() except ValueError: print('Error: Could not parse server response. Event not sent') sys.exit(7) for err in j['errors']: print('Error: {}'.format(err['message'])) sys.exit(8) if __name__ == "__main__": main() briandconnelly-pyfttt-926f71a/pyfttt/sending.py000066400000000000000000000015711313571260400217470ustar00rootroot00000000000000# -*- coding: utf-8 -*- """Handle sending API requests to the IFTTT Webhooks Channel""" import requests 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) briandconnelly-pyfttt-926f71a/requirements.txt000066400000000000000000000000161313571260400216710ustar00rootroot00000000000000requests>=2.7 briandconnelly-pyfttt-926f71a/setup.cfg000066400000000000000000000000341313571260400202260ustar00rootroot00000000000000[bdist_wheel] universal = 1 briandconnelly-pyfttt-926f71a/setup.py000066400000000000000000000042571313571260400201320ustar00rootroot00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- """ Script for installing pyfttt. To install, run: python setup.py install """ # Modified from https://github.com/pypa/sampleproject/blob/master/setup.py from setuptools import setup, find_packages from codecs import open from os import path import sys if sys.argv[-1] == 'setup.py': print("To install pyfttt, run 'python setup.py install'\n") if sys.version_info[:2] < (2, 7): print("pyfttt requires Python 2.7 or later (%d.%d detected)." % sys.version_info[:2]) sys.exit(-1) here = path.abspath(path.dirname(__file__)) setup( name='pyfttt', version='0.3.2', description='Python tools for interacting with the IFTTT Webhooks Channel', long_description='pyfttt is a lightweight package for sending events to the IFTTT Webhooks Channel. Currently, it only supports sending events, but future releases may include a webserver for receiving events.', url='https://github.com/briandconnelly/pyfttt', author='Brian Connelly', author_email='bdc@bconnelly.net', license='BSD', # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: End Users/Desktop', 'License :: OSI Approved :: BSD License', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', ], # What does your project relate to? keywords='IFTTT automation', # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). packages=find_packages(exclude=['contrib', 'docs', 'tests*']), install_requires=['requests>=2.7'], extras_require={}, package_data={}, data_files=[], # To provide executable scripts, use entry points in preference to the # "scripts" keyword. Entry points provide cross-platform support and allow # pip to create the appropriate form of executable for the target platform. entry_points={ 'console_scripts': [ 'pyfttt=pyfttt.cmd_script:main', ], }, )