Skip to content

Commit

Permalink
Merge branch 'tjbenator-pushover-exposed'
Browse files Browse the repository at this point in the history
  • Loading branch information
dschep committed Feb 6, 2016
2 parents d903b99 + 97b81e7 commit f497ca4
Showing 1 changed file with 55 additions and 2 deletions.
57 changes: 55 additions & 2 deletions ntfy/backends/pushover.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import requests
import logging


def notify(title, message, user_key,
api_token='aUnsraBiEZVsmrG89AZp47K3S2dX2a', device=None, **kwargs):
api_token='aUnsraBiEZVsmrG89AZp47K3S2dX2a', device=None,
sound=None, priority=0, expire=None,
retry=None, callback=None, **kwargs):
"""
Required parameters:
* ``user_key``
Optional parameters
Optional parameters:
* ``sound``
* ``priority``
* ``expire``
* ``retry``
* ``callback``
* ``access_token`` - use your own application token
* ``device`` - target a device, if omitted, notification is sent to all devices
"""
Expand All @@ -21,6 +29,51 @@ def notify(title, message, user_key,
if device:
data['device'] = device

if sound:
data['sound'] = sound

if priority <= 2 and priority >= -2:
if priority != 0:
data['priority'] = priority

# Expire, Retry, and Callback only apply to an Emergency Priority
if priority == 2:
# Retry can not be less than 30 per the API
if not retry or retry < 30:
logging.getLogger(__name__).error(
'retry is less than 30 or is not set, '
'setting retry to 30 to comply with '
'pushover API requirements')
data['retry'] = 30
else:
data['retry'] = retry

# Expire can not be more than 86400 (24 hours)
if not expire or expire > 86400:
logging.getLogger(__name__).error(
'expire is greater than 86400 seconds or is not set,'
'setting expire to 86400 to comply with'
'pushover API requirements')
data['expire'] = 86400
elif expire <= 86400:
data['expire'] = expire

if callback:
data['callback'] = callback
else:
if retry:
logging.getLogger(__name__).warning(
'Non-emergency, ignoring retry set in config')
if expire:
logging.getLogger(__name__).warning(
'Non-emergency, ignoring expire set in config')
if callback:
logging.getLogger(__name__).warning(
'Non-emergency, ignoring callback set in config')

else:
raise ValueError('priority must be an integer from -2 to 2')

resp = requests.post('https://api.pushover.net/1/messages.json',
data=data)

Expand Down

0 comments on commit f497ca4

Please sign in to comment.