Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apprise Integration #2796

Merged
merged 10 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion builder/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pyinstaller-hooks-contrib==2024.0
altgraph==0.17.4
wrapt==1.16.0
setuptools==69.0.3
certifi

# Required on 32bit Windows, exclude it based on Python-version
importlib_metadata==7.0.1; python_version < '3.10'
Expand Down
File renamed without changes
86 changes: 43 additions & 43 deletions interfaces/Config/templates/config_notify.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,49 @@
</div>
</div>
<!--#end if#-->
<div class="section" id="apprise">
<div class="col2">
<h3>$T('section-Apprise')</h3>
<table>
<tr>
<td><input type="checkbox" name="apprise_enable" id="apprise_enable" value="1" <!--#if int($apprise_enable) > 0 then 'checked="checked"' else ""#--> /></td>
<td><label for="apprise_enable"> $T('opt-apprise_enable')</label></td>
</tr>
</table>
<em>$T('explain-apprise_enable')</em>
$show_cat_box('apprise')
</div>
<div class="col1" <!--#if int($apprise_enable) > 0 then '' else 'style="display:none"'#-->>
<fieldset>
<div class="field-pair">
<label class="config" for="apprise_urls">$T('opt-apprise_urls')</label>
<input type="text" name="apprise_urls" id="apprise_urls" value="$apprise_urls" />
<span class="desc">$T('explain-apprise_urls'). <br>$T('readwiki')</span>
</div>
<div class="field-pair">
<span class="desc">$T('explain-apprise_extra_urls')</span>
</div>
<!--#set $section_label = 'apprise'#-->
<!--#for $type in $notify_types#-->
<div class="field-pair">
<label class="config" for="${section_label}_target_${type}">
$T($notify_types[$type]).replace('/', ' / ')
</label>
<input type="checkbox" name="${section_label}_target_${type}_enable" id="${section_label}_target_${type}_enable" value="1" <!--#if int($getVar($section_label + '_target_' + $type + '_enable')) > 0 then 'checked="checked"' else ""#--> />
<input type="text" name="${section_label}_target_${type}" id="${section_label}_target_${type}" value="$getVar($section_label + '_target_' + $type)" placeholder="$T('opt-apprise_urls')" />
</div>
<!--#end for#-->

<div class="field-pair no-field-pair-bg">
<button class="btn btn-default saveButton"><span class="glyphicon glyphicon-ok"></span> $T('button-saveChanges')</button>
<button class="btn btn-default" type="button" id="test_apprise"><span class="glyphicon glyphicon-comment"></span> $T('testNotify')</button>
</div>
<div class="field-pair result-box">
<div class="alert"></div>
</div>
</fieldset>
</div>
</div>
<div class="section" id="nscript">
<div class="col2">
<h3>$T('section-NScript') <a href="$help_uri#nscript" target="_blank"><span class="glyphicon glyphicon-question-sign"></span></a></h3>
Expand Down Expand Up @@ -363,49 +406,6 @@
</fieldset>
</div>
</div>
<div class="section" id="apprise">
<div class="col2">
<h3>$T('section-Apprise')</h3>
<table>
<tr>
<td><input type="checkbox" name="apprise_enable" id="apprise_enable" value="1" <!--#if int($apprise_enable) > 0 then 'checked="checked"' else ""#--> /></td>
<td><label for="apprise_enable"> $T('opt-apprise_enable')</label></td>
</tr>
</table>
<em>$T('explain-apprise_enable')</em>
$show_cat_box('apprise')
</div>
<div class="col1" <!--#if int($apprise_enable) > 0 then '' else 'style="display:none"'#-->>
<fieldset>
<div class="field-pair">
<label class="config" for="apprise_urls">$T('opt-apprise_urls')</label>
<input type="text" name="apprise_urls" id="apprise_urls" value="$apprise_urls" />
<span class="desc">$T('explain-apprise_urls')</span>
</div>
<hr />
<span class="desc">$T('explain-apprise_extra_urls')</span>
<!--#set $section_label = 'apprise'#-->
<!--#for $type in $notify_types#-->
<div class="field-pair">
<label class="config" for="${section_label}_target_${type}">
$T($notify_types[$type]).replace('/', ' / ')
</label>
<input type="checkbox" name="${section_label}_target_${type}_enable" id="${section_label}_target_${type}_enable" value="1" <!--#if int($getVar($section_label + '_target_' + $type + '_enable')) > 0 then 'checked="checked"' else ""#--> />

<input type="text" name="${section_label}_target_${type}" id="${section_label}_target_${type}" value="$getVar($section_label + '_target_' + $type)" placeholder="${T('default')}" />
</div>
<!--#end for#-->

<div class="field-pair no-field-pair-bg">
<button class="btn btn-default saveButton"><span class="glyphicon glyphicon-ok"></span> $T('button-saveChanges')</button>
<button class="btn btn-default" type="button" id="test_apprise"><span class="glyphicon glyphicon-comment"></span> $T('testNotify')</button>
</div>
<div class="field-pair result-box">
<div class="alert"></div>
</div>
</fieldset>
</div>
</div>
</form>
</div><!-- /colmask -->

Expand Down
18 changes: 6 additions & 12 deletions requirements.txt
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pyYAML is needed by Apprise. Zoggys advice to define these 2 entries was a really good one. I don't think we should remove it from the requirements.txt.

Also, the way it was gave every system that had the ability to leverage the binary package to do so yet still be compatible for the systems that couldn't

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,10 @@ pyobjc-framework-Cocoa==10.1; sys_platform == 'darwin'
# Linux notifications
notify2==0.3.1; sys_platform != 'win32' and sys_platform != 'darwin'

# Optional support for *nix tray icon.
# Note that pygobject depends on pycairo, which requires pkg-config and cairo headers.
# See https://pycairo.readthedocs.io/en/latest/getting_started.html
# Uncomment line below or manually install after installing requirements.
# pygobject>=3.10.2; sys_platform != 'win32' and sys_platform != 'darwin'

# PyYAML does not have binary packages for Mac Users
PyYAML==6.0.1 --no-binary=PyYAML; sys_platform == 'darwin'
PyYAML==6.0.1; sys_platform != 'darwin'

# Apprise Requirements
requests==2.31.0
requests-oauthlib==1.3.1
Safihre marked this conversation as resolved.
Show resolved Hide resolved
PyYAML==6.0.1
markdown==3.5.2
paho-mqtt==1.6.1

Expand All @@ -74,8 +65,11 @@ oauthlib==3.2.2
PyJWT==2.8.0
blinker==1.7.0

# Markdown Requirements
importlib-metadata==7.0.1
# Optional support for *nix tray icon.
# Note that pygobject depends on pycairo, which requires pkg-config and cairo headers.
# See https://pycairo.readthedocs.io/en/latest/getting_started.html
# Uncomment line below or manually install after installing requirements.
# pygobject>=3.10.2; sys_platform != 'win32' and sys_platform != 'darwin'

# Optional support for system power management on *nix.
# Requires libdbus-1-dev to be installed.
Expand Down
38 changes: 16 additions & 22 deletions sabnzbd/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,13 @@ def get_target(notification_type: str, section: str) -> Union[str, bool, None]:
"""Check target of `notification_type` in `section` if enabled is set"""
try:
if sabnzbd.config.get_config(section, "%s_target_%s_enable" % (section, notification_type))() > 0:
result = sabnzbd.config.get_config(section, "%s_target_%s" % (section, notification_type))().strip()
if result:
if result := sabnzbd.config.get_config(section, "%s_target_%s" % (section, notification_type))():
return result

else:
# Use Default
return True

# Use Default
return True
except TypeError:
logging.debug("Incorrect Notify option %s:%s_target_%s", section, section, notification_type)
return None

return False
return False


Expand Down Expand Up @@ -331,10 +326,9 @@ def send_apprise(title, msg, notification_type, force=False, test=None):
app_id="SABnzbd",
app_desc="SABnzbd Notification",
app_url="https://sabnzbd.org/",
image_path_mask=os.path.join(os.path.dirname(__file__), "apprise", "apprise-{TYPE}.png"),
image_url_mask="https://raw.githubusercontent.com/sabnzbd/sabnzbd.github.io/master/images/icons/apprise/{TYPE}.png",
image_url_logo="https://raw.githubusercontent.com/sabnzbd/sabnzbd.github.io/master/images/icons/"
"apple-touch-icon-180x180-precomposed.png",
image_path_mask=os.path.join(sabnzbd.DIR_PROG, "icons", "apprise", "apprise-{TYPE}.png"),
image_url_mask="https://sabnzbd.org/images/icons/apprise/{TYPE}.png",
image_url_logo="https://sabnzbd.org/images/icons/apple-touch-icon-180x180-precomposed.png",
)

# Initialize our Apprise Instance
Expand All @@ -346,25 +340,25 @@ def send_apprise(title, msg, notification_type, force=False, test=None):
if target is True:
# Use default list
apobj.add(urls)

else: # Target is string of URLs to over-ride with
elif not apobj.add(target):
# Target is string of URLs to over-ride with
# Store our URL and assign our key
if not apobj.add(target):
logging.warning(
"Key: %s - %s", notification_type, T("One or more Apprise URLs could not be loaded.")
)

logging.warning("%s - %s", notification_type, T("One or more Apprise URLs could not be loaded."))
else:
# Nothing to notify
return ""

else:
# Use default list
apobj.add(urls)

try:
# The below notifies anything added to our list
if not apobj.notify(body=msg, title=title, notify_type=n_map[notification_type], body_format="text"):
if not apobj.notify(
body=msg,
title=title,
notify_type=n_map[notification_type],
body_format=apprise.NotifyFormat.TEXT,
):
return T("Failed to send one or more Apprise Notifications")

except:
Expand Down
10 changes: 5 additions & 5 deletions sabnzbd/skintext.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,13 +673,13 @@
"explain-pushbullet_device": TT("Device to which message should be sent"), #: Pushbullet settings
"section-Apprise": TT("Apprise"), #: Header for Apprise notification section
"opt-apprise_enable": TT("Enable Apprise notifications"), #: Apprise settings
"explain-apprise_enable": TT("Send notifications using Apprise URLs"), #: Apprise settings
"explain-apprise_enable": TT(
"Send notifications using Apprise to almost any notification service"
), #: Apprise settings
"opt-apprise_urls": TT("Default Apprise URLs"), #: Apprise settings
"explain-apprise_urls": TT("Use a comma and/or space to identify more then one URL"), #: Apprise settings
"explain-apprise_urls": TT("Use a comma and/or space to identify more then one URL."), #: Apprise settings
"explain-apprise_extra_urls": TT(
"Optionally override the default URL(s) for specific cases. To disable a notification for a specific category:"
" simply enable it below, but do not provide it a URL to trigger off of. Alternatively, use comma and/or "
"space to identify more then one Apprise URL overide."
"Override the default URLs for specific notification types below, if desired."
), #: Apprise settings
"section-NScript": TT("Notification Script"), #: Header for Notification Script notification section
"opt-nscript_enable": TT("Enable notification script"), #: Notification Script settings
Expand Down