diff --git a/data/interfaces/bookstrap/config.html b/data/interfaces/bookstrap/config.html
index b708d43a..305ad5d4 100644
--- a/data/interfaces/bookstrap/config.html
+++ b/data/interfaces/bookstrap/config.html
@@ -1748,6 +1748,52 @@
+
+ <%
+ if lazylibrarian.CONFIG['USE_CUSTOM'] == True:
+ checked = 'checked="checked"'
+ else:
+ checked = ''
+ %>
+
+
+
@@ -2499,6 +2545,26 @@
}
});
+ if ($("#use_custom").is(":checked"))
+ {
+ $("#customoptions").show();
+ }
+ else
+ {
+ $("#customoptions").hide();
+ }
+
+ $("#use_custom").click(function(){
+ if ($("#use_custom").is(":checked"))
+ {
+ $("#customoptions").slideDown();
+ }
+ else
+ {
+ $("#customoptions").slideUp();
+ }
+ });
+
if ($("#use_email").is(":checked"))
{
$("#emailoptions").show();
@@ -2567,6 +2633,12 @@
});
+ $('#testCustom').click(function () {
+ $.get("testCustom",
+ function (data) { window.alert(data) });
+
+ });
+
$('#testEmail').click(function () {
$.get("testEmail",
function (data) { window.alert(data) });
diff --git a/example_custom_notification.py b/example_custom_notification.py
new file mode 100755
index 00000000..bf2eb8c7
--- /dev/null
+++ b/example_custom_notification.py
@@ -0,0 +1,25 @@
+#!/usr/bin/python
+# The parameter list passed is a list of database columns (name and data)
+# for a book or magazine. Read them back into a dictionary.
+# For this example, just write the dictionary to a file
+import sys
+err = ''
+try:
+ args = sys.argv[1:]
+except Exception as e:
+ err = str(e)
+with open('notification.out', 'w') as f:
+ if err:
+ f.write(err)
+ else:
+ try:
+ n = len(args)
+ mydict = {}
+ while n:
+ mydict[args[n-2]] = args[n-1]
+ n -= 2
+ except Exception as e:
+ f.write(str(e))
+
+ for item in mydict:
+ f.write("%s: %s\n" % (item, mydict[item]))
diff --git a/lazylibrarian/__init__.py b/lazylibrarian/__init__.py
index 7a0e6bd0..d302fa50 100644
--- a/lazylibrarian/__init__.py
+++ b/lazylibrarian/__init__.py
@@ -296,6 +296,10 @@ CONFIG_DEFINITIONS = {
'SLACK_NOTIFY_ONSNATCH': ('bool', 'Slack', 0),
'SLACK_NOTIFY_ONDOWNLOAD': ('bool', 'Slack', 0),
'SLACK_TOKEN': ('str', 'Slack', ''),
+ 'USE_CUSTOM': ('bool', 'Custom', 0),
+ 'CUSTOM_NOTIFY_ONSNATCH': ('bool', 'Custom', 0),
+ 'CUSTOM_NOTIFY_ONDOWNLOAD': ('bool', 'Custom', 0),
+ 'CUSTOM_SCRIPT': ('str', 'Custom', ''),
'USE_EMAIL': ('bool', 'Email', 0),
'EMAIL_NOTIFY_ONSNATCH': ('bool', 'Email', 0),
'EMAIL_NOTIFY_ONDOWNLOAD': ('bool', 'Email', 0),
diff --git a/lazylibrarian/notifiers/__init__.py b/lazylibrarian/notifiers/__init__.py
index 90100850..ee9f0be8 100644
--- a/lazylibrarian/notifiers/__init__.py
+++ b/lazylibrarian/notifiers/__init__.py
@@ -24,6 +24,7 @@ import pushbullet
import pushover
import slack
import tweet
+import custom_notify
# online
twitter_notifier = tweet.TwitterNotifier()
@@ -34,6 +35,8 @@ androidpn_notifier = androidpn.AndroidPNNotifier()
nma_notifier = nma.NMA_Notifier()
slack_notifier = slack.SlackNotifier()
email_notifier = email_notify.EmailNotifier()
+#
+custom_notifier = custom_notify.CustomNotifier()
notifiers = [
twitter_notifier,
@@ -46,12 +49,13 @@ notifiers = [
email_notifier
]
+def custom_notify(bookid):
+ custom_notifier.notify_download(bookid)
def notify_download(title):
for n in notifiers:
n.notify_download(title)
-
def notify_snatch(title):
for n in notifiers:
n.notify_snatch(title)
diff --git a/lazylibrarian/notifiers/custom_notify.py b/lazylibrarian/notifiers/custom_notify.py
new file mode 100644
index 00000000..6cb1432d
--- /dev/null
+++ b/lazylibrarian/notifiers/custom_notify.py
@@ -0,0 +1,85 @@
+# This file is part of LazyLibrarian.
+#
+# LazyLibrarian is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# LazyLibrarian is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with LazyLibrarian. If not, see .
+
+import lazylibrarian
+import subprocess
+from lazylibrarian import logger, database
+from lazylibrarian.common import notifyStrings, NOTIFY_SNATCH, NOTIFY_DOWNLOAD
+
+
+class CustomNotifier:
+ @staticmethod
+ def _notify(message, event, force=False):
+
+ # suppress notifications if the notifier is disabled but the notify options are checked
+ if not lazylibrarian.CONFIG['USE_CUSTOM'] and not force:
+ return False
+
+ subject = event
+ text = message
+
+ logger.debug('Custom Event: %s' % event)
+ logger.debug('Custom Message: %s' % message)
+ myDB = database.DBConnection()
+ if subject == "Test":
+ # grab the first entry in the book table
+ data = myDB.match('SELECT * from books')
+ else:
+ # message is a bookid or a magazineid
+ data = myDB.match('SELECT * from books where BookID="%s"' % message)
+ if not data:
+ data = myDB.match('SELECT * from magazines where BookID="%s"' % message)
+ dictionary = dict(zip(data.keys(), data))
+
+ try:
+ # call the custom notifier script here, passing dictionary deconstructed as strings
+ if lazylibrarian.CONFIG['CUSTOM_SCRIPT']:
+ params = [lazylibrarian.CONFIG['CUSTOM_SCRIPT']]
+ for item in dictionary:
+ params.append(item)
+ if hasattr(dictionary[item], 'encode'):
+ params.append(dictionary[item].encode('utf-8'))
+ else:
+ params.append(str(dictionary[item]))
+
+ res = subprocess.check_output(params, stderr=subprocess.STDOUT)
+ if len(res):
+ return res
+ return True
+ else:
+ logger.warn('Error sending custom notification: Check config')
+ return False
+
+ except Exception as e:
+ logger.warn('Error sending custom notification: %s' % e)
+ return False
+
+ #
+ # Public functions
+ #
+
+ def notify_snatch(self, title):
+ if lazylibrarian.CONFIG['EMAIL_NOTIFY_ONSNATCH']:
+ self._notify(message=title, event=notifyStrings[NOTIFY_SNATCH])
+
+ def notify_download(self, title):
+ if lazylibrarian.CONFIG['EMAIL_NOTIFY_ONDOWNLOAD']:
+ self._notify(message=title, event=notifyStrings[NOTIFY_DOWNLOAD])
+
+ def test_notify(self, title="Test"):
+ return self._notify(message=title, event="Test", force=True)
+
+
+notifier = CustomNotifier
diff --git a/lazylibrarian/postprocess.py b/lazylibrarian/postprocess.py
index b3e1846f..ebdfe49b 100644
--- a/lazylibrarian/postprocess.py
+++ b/lazylibrarian/postprocess.py
@@ -32,7 +32,7 @@ from lazylibrarian.gr import GoodReads
from lazylibrarian.importer import addAuthorToDB
from lazylibrarian.librarysync import get_book_info, find_book_in_db, LibraryScan
from lazylibrarian.magazinescan import create_id, create_cover
-from lazylibrarian.notifiers import notify_download
+from lazylibrarian.notifiers import notify_download, custom_notify
from lib.deluge_client import DelugeRPCClient
from lib.fuzzywuzzy import fuzz
@@ -496,6 +496,7 @@ def processDir(reset=False):
logger.info('Successfully processed: %s' % global_name)
ppcount += 1
+ custom_notify(book['BookID'])
if internet():
notify_download("%s from %s at %s" % (global_name, book['NZBprov'], now()))
else:
@@ -707,6 +708,7 @@ def import_book(pp_path=None, bookID=None):
logger.debug("Not removing original files as in download root")
logger.info('Successfully processed: %s' % global_name)
+ custom_notify(bookID)
if internet():
notify_download("%s %s at %s" % (global_name, snatched_from, now()))
return True