Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: CI

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.x

- name: Install dependencies
run: |
pip install yapf
shell: bash

- name: Format code with yapf
run: |
set -e
yapf -r ntfy -d
[ "$(yapf -r ntfy -d | wc -l)" -eq 0 ]
shell: bash
test:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "pypy-3.10"]
exclude:
- os: macos-latest
python-version: pypy-3.10
- os: windows-latest
python-version: pypy-3.10
runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: |
setup.py
test-requirements.txt

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools
pip install .
pip install -r test-requirements.txt
pip install twine pytest-cov

- name: Run tests
run: |
pytest --cov=ntfy --ignore 'tests/test_xmpp.py' -k 'not test_xmpp' tests

- name: Upload coverage to Coveralls
uses: coverallsapp/github-action@v2
with:
flag-name: run-${{ join(matrix.*, '-') }}
parallel: true

finish:
needs: test
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- name: Signal test completion to coverage
uses: coverallsapp/github-action@v2
with:
parallel-finished: true
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,16 @@ title: Customized Title

## Testing

Additional requirements required for the test suite are defined in `test-requirements.txt`.

```shell
pip install -r test-requirements.txt
```

To run the test suite, run the following command:

``` shell
python setup.py test
pytest test
```

## Contributors
Expand Down
12 changes: 6 additions & 6 deletions ntfy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ def notify(message, title, config=None, **kwargs):
continue

try:
notify_ret = notifier.notify(
message=message,
title=title,
retcode=retcode,
**backend_config)
notify_ret = notifier.notify(message=message,
title=title,
retcode=retcode,
**backend_config)
if notify_ret:
ret = notify_ret
except (SystemExit, KeyboardInterrupt):
Expand All @@ -67,7 +66,8 @@ def notify(message, title, config=None, **kwargs):

args, _, _, defaults, *_ = getfullargspec(notifier.notify)
possible_args = set(args)
required_args = set(args) if defaults is None else set(args[:-len(defaults)])
required_args = set(args) if defaults is None else set(
args[:-len(defaults)])
required_args -= set(['title', 'message', 'retcode'])
unknown_args = set(backend_config) - possible_args
missing_args = required_args - set(backend_config)
Expand Down
1 change: 1 addition & 0 deletions ntfy/backends/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


class DefaultNotifierError(Exception):

def __init__(self, exception, module):
self.exception = exception
self.module = module
Expand Down
8 changes: 4 additions & 4 deletions ntfy/backends/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def notify(title,
bus = dbus.SessionBus()
dbus_obj = bus.get_object('org.freedesktop.Notifications',
'/org/freedesktop/Notifications')
dbus_iface = dbus.Interface(
dbus_obj, dbus_interface='org.freedesktop.Notifications')
dbus_iface = dbus.Interface(dbus_obj,
dbus_interface='org.freedesktop.Notifications')

hints = {}

Expand Down Expand Up @@ -61,5 +61,5 @@ def notify(title,
hints.update({'sound-file': soundfile})

message = message.replace('&', '&')
dbus_iface.Notify('ntfy', 0, "" or icon, title,
message, [], hints, int(timeout))
dbus_iface.Notify('ntfy', 0, "" or icon, title, message, [], hints,
int(timeout))
10 changes: 9 additions & 1 deletion ntfy/backends/matrix.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from __future__ import unicode_literals
from matrix_client.client import MatrixClient

def notify(title, message, url, roomId, userId=None, token=None, password=None, retcode=None):

def notify(title,
message,
url,
roomId,
userId=None,
token=None,
password=None,
retcode=None):

client = MatrixClient(url)
if password is not None:
Expand Down
12 changes: 6 additions & 6 deletions ntfy/backends/notifico.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def notify(title, message, retcode=None, webhook=None):
logger.error('please set webhook variable under '
'notifico backend of the config file')
return
response = requests.get(
webhook,
params={
'payload': '{title}\n{message}'.format(
title=title, message=message)
})
response = requests.get(webhook,
params={
'payload':
'{title}\n{message}'.format(title=title,
message=message)
})
response.raise_for_status()
8 changes: 7 additions & 1 deletion ntfy/backends/ntfy_sh.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import requests


def notify(title, message, topic, host='https://ntfy.sh', user=None, password=None, **kwargs):
def notify(title,
message,
topic,
host='https://ntfy.sh',
user=None,
password=None,
**kwargs):
auth_kwarg = {'auth': (user, password)} if user and password else {}

requests.post(
Expand Down
14 changes: 8 additions & 6 deletions ntfy/backends/prowl.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@ def notify(title,
if MIN_PRIORITY <= priority <= MAX_PRIORITY:
data['priority'] = priority
else:
raise ValueError('priority must be an integer from {:d} to {:d}'
.format(MIN_PRIORITY, MAX_PRIORITY))
raise ValueError(
'priority must be an integer from {:d} to {:d}'.format(
MIN_PRIORITY, MAX_PRIORITY))

if url is not None:
data['url'] = url

if provider_key is not None:
data['providerkey'] = provider_key

resp = requests.post(
API_URL, data=data, headers={
'User-Agent': USER_AGENT,
})
resp = requests.post(API_URL,
data=data,
headers={
'User-Agent': USER_AGENT,
})

resp.raise_for_status()
5 changes: 3 additions & 2 deletions ntfy/backends/pushbullet.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def notify(title,

headers = {'Access-Token': access_token, 'User-Agent': USER_AGENT}

resp = requests.post(
'https://api.pushbullet.com/v2/pushes', data=data, headers=headers)
resp = requests.post('https://api.pushbullet.com/v2/pushes',
data=data,
headers=headers)

resp.raise_for_status()
11 changes: 5 additions & 6 deletions ntfy/backends/pushover.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,11 @@ def notify(title,
else:
raise ValueError('priority must be an integer from -2 to 2')

resp = requests.post(
'https://api.pushover.net/1/messages.json',
data=data,
headers={
'User-Agent': USER_AGENT,
})
resp = requests.post('https://api.pushover.net/1/messages.json',
data=data,
headers={
'User-Agent': USER_AGENT,
})

if resp.status_code == 429:
print("ntfy's default api_token has reached pushover's rate limit")
Expand Down
28 changes: 15 additions & 13 deletions ntfy/backends/slack_webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ def notify(title, message, url, user, **kwargs):
requests.post(
url,
json={
"username": "ntfy",
"icon_url": "https://ntfy.readthedocs.io/en/latest/_static/logo.png",
"text": "{0}\n{1}".format(title, message),
"channel": user,
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*{0}* {1}".format(title, message),
},
}
],
"username":
"ntfy",
"icon_url":
"https://ntfy.readthedocs.io/en/latest/_static/logo.png",
"text":
"{0}\n{1}".format(title, message),
"channel":
user,
"blocks": [{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*{0}* {1}".format(title, message),
},
}],
},
)
3 changes: 2 additions & 1 deletion ntfy/backends/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
config_dir = user_config_dir('ntfy', 'dschep')
config_file = path.join(config_dir, 'telegram.ini')


def notify(title, message, retcode=None):
"""Sends message over Telegram using telegram-send, title is ignored."""
if not path.exists(config_file):
if not path.exists(config_dir):
makedirs(config_dir)
print("Follow the instructions to configure the Telegram backend.\n")
asyncio.run(configure(config_file))
asyncio.run(send(messages=[message], conf=config_file))
asyncio.run(send(messages=[message], conf=config_file))
13 changes: 8 additions & 5 deletions ntfy/backends/win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def notify(title, message, icon=icon.ico, retcode=None):
import win32gui

class WindowsBalloonTip:

def __init__(self, title, msg):
message_map = {
win32con.WM_DESTROY: self.OnDestroy,
Expand All @@ -28,15 +29,17 @@ def __init__(self, title, msg):
classAtom = win32gui.RegisterClass(wc)
# Create the Window.
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
self.hwnd = win32gui.CreateWindow(
classAtom, "Taskbar", style, 0, 0, win32con.CW_USEDEFAULT,
win32con.CW_USEDEFAULT, 0, 0, hinst, None)
self.hwnd = win32gui.CreateWindow(classAtom, "Taskbar", style, 0,
0, win32con.CW_USEDEFAULT,
win32con.CW_USEDEFAULT, 0, 0,
hinst, None)
win32gui.UpdateWindow(self.hwnd)
iconPathName = os.path.abspath(icon)
icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
try:
hicon = win32gui.LoadImage(
hinst, iconPathName, win32con.IMAGE_ICON, 0, 0, icon_flags)
hicon = win32gui.LoadImage(hinst, iconPathName,
win32con.IMAGE_ICON, 0, 0,
icon_flags)
except:
hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
flags = win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP
Expand Down
Loading