Skip to content

Commit

Permalink
actually yapfify
Browse files Browse the repository at this point in the history
  • Loading branch information
dschep committed May 26, 2017
1 parent 4b3c230 commit 0659971
Show file tree
Hide file tree
Showing 18 changed files with 134 additions and 140 deletions.
18 changes: 11 additions & 7 deletions ntfy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

__version__ = '2.4.3'


_user_home = path.expanduser('~')
_cwd = getcwd()
if name != 'nt' and _cwd.startswith(_user_home):
default_title = '{}@{}:{}'.format(getuser(), gethostname(),
path.join('~', _cwd[len(_user_home)+1:]))
default_title = '{}@{}:{}'.format(getuser(),
gethostname(),
path.join('~',
_cwd[len(_user_home) + 1:]))
else:
default_title = '{}@{}:{}'.format(getuser(), gethostname(), _cwd)

Expand All @@ -34,8 +35,8 @@ def notify(message, title, config=None, **kwargs):
backend = backend_config.pop('backend')

if title is None:
title = backend_config.pop('title', config.get('title',
default_title))
title = backend_config.pop('title',
config.get('title', default_title))
elif 'title' in backend_config:
del backend_config['title']

Expand All @@ -48,8 +49,11 @@ 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 Down
4 changes: 2 additions & 2 deletions ntfy/backends/insta.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def notify(title, message, event_name, appid, secret, trackers, retcode=None):
if len(msgs) != len(trackers):
logger.error(('Wrong number of messages! There are {} trackers so you '
'have to provide {} messages. Remember to separate each '
'message with \':\' (example: send "msg1:msg2")'
).format(len(trackers), len(trackers)))
'message with \':\' (example: send "msg1:msg2")').format(
len(trackers), len(trackers)))
raise WrongMessageCountException()

to_send = {}
Expand Down
8 changes: 4 additions & 4 deletions ntfy/backends/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def notify(title, message, icon=icon.png, urgency=None, retcode=0):
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 All @@ -42,5 +42,5 @@ def notify(title, message, icon=icon.png, urgency=None, retcode=0):
hints = {'urgency': dbus.Byte(2)}

message = message.replace('&', '&')
dbus_iface.Notify('ntfy', 0, path.abspath(icon), title, message, [], hints,
-1)
dbus_iface.Notify('ntfy', 0,
path.abspath(icon), title, message, [], hints, -1)
14 changes: 8 additions & 6 deletions ntfy/backends/notifico.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ def notify(title, message, retcode=None, webhook=None):

logger = logging.getLogger(__name__)
if webhook is None:
logger.error(
'please set webhook variable under '
'notifico backend of the config file')
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()
6 changes: 2 additions & 4 deletions ntfy/backends/prowl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from ..config import USER_AGENT


NTFY_API_KEY = '7fb59b2bedc4df26afa306d5dc54495b6394295a'
API_URL = 'https://api.prowlapp.com/publicapi/add'
MIN_PRIORITY = -2
Expand Down Expand Up @@ -43,8 +42,7 @@ def notify(title,
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: 1 addition & 4 deletions ntfy/backends/pushalot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from ..config import USER_AGENT


# URL to pushalot.com notification sending endpoint
PUSHALOT_API_URL = 'https://pushalot.com/api/sendmessage'

Expand Down Expand Up @@ -54,7 +53,5 @@ def notify(title,
data['IsSilent'] = 'True'

headers = {'User-Agent': USER_AGENT}
response = requests.post(PUSHALOT_API_URL,
data=data,
headers=headers)
response = requests.post(PUSHALOT_API_URL, data=data, headers=headers)
response.raise_for_status()
11 changes: 7 additions & 4 deletions ntfy/backends/pushbullet.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ def notify(title,
email or send an email if they aren't a pushullet user
"""

data = {'type': 'note', 'title': title, 'body': message, }
data = {
'type': 'note',
'title': title,
'body': message,
}
if device_iden is not None:
data['device_iden'] = device_iden
if email is not None:
data['email'] = email

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()
4 changes: 1 addition & 3 deletions ntfy/backends/pushjet.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ def notify(title,
if endpoint is None:
endpoint = 'https://api.pushjet.io'

resp = requests.post(endpoint + '/message',
data=data,
headers=headers)
resp = requests.post(endpoint + '/message', data=data, headers=headers)

resp.raise_for_status()
15 changes: 8 additions & 7 deletions ntfy/backends/pushover.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ def notify(title,
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')
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
Expand Down Expand Up @@ -105,9 +105,10 @@ 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
10 changes: 2 additions & 8 deletions ntfy/backends/simplepush.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
from ..config import USER_AGENT


def notify(title,
message,
key,
event=None,
retcode=None):
def notify(title, message, key, event=None, retcode=None):
"""
Required paramter:
* ``key`` - The Simplepush identification key, created by
Expand All @@ -30,8 +26,6 @@ def notify(title,

endpoint = "https://api.simplepush.io"

resp = requests.post(endpoint + '/send',
data=data,
headers=headers)
resp = requests.post(endpoint + '/send', data=data, headers=headers)

resp.raise_for_status()
1 change: 0 additions & 1 deletion ntfy/backends/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from appdirs import user_config_dir
from telegram_send import send, configure


config_dir = user_config_dir('ntfy', 'dschep')
config_file = path.join(config_dir, 'telegram.ini')

Expand Down
4 changes: 1 addition & 3 deletions ntfy/backends/termux.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
from subprocess import check_call


def notify(title,
message,
retcode=None):
def notify(title, message, retcode=None):
"""
Termux:API backend.
"""
Expand Down
9 changes: 5 additions & 4 deletions ntfy/backends/win32.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def notify(title, message, icon=icon.ico, retcode=None):

class WindowsBalloonTip:
def __init__(self, title, msg):
message_map = {win32con.WM_DESTROY: self.OnDestroy, }
message_map = {
win32con.WM_DESTROY: self.OnDestroy,
}
# Register the Window class.
wc = win32gui.WNDCLASS()
hinst = wc.hInstance = win32api.GetModuleHandle(None)
Expand All @@ -33,9 +35,8 @@ def __init__(self, title, msg):
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
8 changes: 5 additions & 3 deletions ntfy/backends/xmpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ def start(self, event):

self.send_presence()
self.get_roster()
msg_args = {'mto': self.recipient,
'msubject': self.title,
'mbody': self.msg}
msg_args = {
'mto': self.recipient,
'msubject': self.title,
'mbody': self.msg
}
if self.mtype:
msg_args['mtype'] = self.mtype

Expand Down
Loading

0 comments on commit 0659971

Please sign in to comment.