Custom notifier examples and snatch/download

This commit is contained in:
Phil Borman 2017-03-16 18:18:55 +01:00
parent a764703e17
commit f40ba0f77c
11 changed files with 77 additions and 8 deletions

View File

@ -1480,6 +1480,47 @@
</div>
</div>
</fieldset>
<fieldset>
<BR>
<h3>Custom</h3>
<div class="row checkbox">
<%
if lazylibrarian.CONFIG['USE_SLACK'] == True:
checked = 'checked="checked"'
else:
checked = ''
%>
<input type="checkbox" name="use_custom" id="custom" value="1" ${checked} />
<label>Enable Custom Notifications</label>
</div>
<div id="customoptions">
<div class="row">
<%
if lazylibrarian.CONFIG['CUSTOM_NOTIFY_ONSNATCH'] == True:
checked = 'checked="checked"'
else:
checked = ''
%>
<input type="checkbox" name="custom_notify_onsnatch" value="1" ${checked} />Notify on snatch
</div>
<div class="row">
<%
if lazylibrarian.CONFIG['CUSTOM_NOTIFY_ONDOWNLOAD'] == True:
checked = 'checked="checked"'
else:
checked = ''
%>
<input type="checkbox" name="custom_notify_ondownload" value="1" ${checked} />Notify on download
</div>
<div class="row">
<input type="text" name="custom_script" value="${lazylibrarian.CONFIG['CUSTOM_SCRIPT']}" size="26" placeholder="Custom script">
</div>
<div class="row">
<input type="button" value="Test Custom" id="testCustom">
<br><small>Save settings before testing</small>
</div>
</div>
</fieldset>
</td>
</table>
</div>

View File

@ -22,4 +22,5 @@ with open('notification.out', 'w') as f:
f.write(str(e))
for item in mydict:
# column name: value
f.write("%s: %s\n" % (item, mydict[item]))

17
example_custom_notification.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
# The parameter list passed is a list of database columns (name and data)
# for a book or magazine.
# For this example, just write the arguments to a file
ofile='notification.out'
echo -n "" > $ofile
arg=1
numargs=$#
while (( arg < numargs)); do
# column name
echo -n "${!arg}: " >> $ofile
(( arg += 1 ))
# value
echo "${!arg}" >> $ofile
(( arg += 1 ))
done

View File

@ -49,9 +49,12 @@ notifiers = [
email_notifier
]
def custom_notify(bookid):
def custom_notify_download(bookid):
custom_notifier.notify_download(bookid)
def custom_notify_snatch(bookid):
custom_notifier.notify_snatch(bookid)
def notify_download(title):
for n in notifiers:
n.notify_download(title)

View File

@ -42,6 +42,7 @@ class CustomNotifier:
if not data:
data = myDB.match('SELECT * from magazines where BookID="%s"' % message)
dictionary = dict(zip(data.keys(), data))
dictionary['Event'] = event
try:
# call the custom notifier script here, passing dictionary deconstructed as strings

View File

@ -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, custom_notify
from lazylibrarian.notifiers import notify_download, custom_notify_download
from lib.deluge_client import DelugeRPCClient
from lib.fuzzywuzzy import fuzz
@ -496,7 +496,7 @@ def processDir(reset=False):
logger.info('Successfully processed: %s' % global_name)
ppcount += 1
custom_notify(book['BookID'])
custom_notify_download(book['BookID'])
if internet():
notify_download("%s from %s at %s" % (global_name, book['NZBprov'], now()))
else:

View File

@ -24,7 +24,7 @@ from lazylibrarian import logger, database
from lazylibrarian.common import scheduleJob, internet
from lazylibrarian.formatter import plural, now, unaccented_str, replace_all, unaccented, \
nzbdate2format, getList, month2num, datecompare, check_int, check_year
from lazylibrarian.notifiers import notify_snatch
from lazylibrarian.notifiers import notify_snatch, custom_notify_snatch
from lazylibrarian.providers import IterateOverNewzNabSites, IterateOverTorrentSites, IterateOverRSSSites
from lazylibrarian.searchnzb import NZBDownloadMethod
from lazylibrarian.searchtorrents import TORDownloadMethod
@ -470,6 +470,7 @@ def search_magazines(mags=None, reset=False):
logger.info('Downloading %s from %s' % (magazine['nzbtitle'], magazine["nzbprov"]))
notify_snatch("%s from %s at %s" %
(unaccented(magazine['nzbtitle']), magazine["nzbprov"], now()))
custom_notify_snatch(magazine['bookid'])
scheduleJob(action='Start', target='processDir')
if reset:

View File

@ -23,7 +23,7 @@ from lazylibrarian import logger, database, providers, nzbget, sabnzbd, classes,
from lazylibrarian.cache import fetchURL
from lazylibrarian.common import scheduleJob, setperm, internet
from lazylibrarian.formatter import plural, unaccented_str, replace_all, getList, now, check_int
from lazylibrarian.notifiers import notify_snatch
from lazylibrarian.notifiers import notify_snatch, custom_notify_snatch
from lazylibrarian.searchtorrents import TORDownloadMethod
from lib.fuzzywuzzy import fuzz
@ -238,6 +238,7 @@ def processResultList(resultlist, book, searchtype):
logger.info('Downloading %s from %s' % (newValueDict["NZBtitle"], newValueDict["NZBprov"]))
notify_snatch("%s from %s at %s" %
(newValueDict["NZBtitle"], newValueDict["NZBprov"], now()))
custom_notify_snatch(newValueDict["BookID"])
scheduleJob(action='Start', target='processDir')
return True + True # we found it
else:

View File

@ -21,7 +21,7 @@ import lazylibrarian
from lazylibrarian import logger, database
from lazylibrarian.common import scheduleJob, internet
from lazylibrarian.formatter import plural, unaccented_str, replace_all, getList, check_int, now
from lazylibrarian.notifiers import notify_snatch
from lazylibrarian.notifiers import notify_snatch, custom_notify_snatch
from lazylibrarian.providers import IterateOverRSSSites, get_searchterm
from lazylibrarian.searchnzb import NZBDownloadMethod
from lazylibrarian.searchtorrents import TORDownloadMethod
@ -223,6 +223,7 @@ def processResultList(resultlist, authorname, bookname, book, searchtype):
logger.info('Downloading %s from %s' % (newValueDict["NZBtitle"], newValueDict["NZBprov"]))
notify_snatch("%s from %s at %s" %
(newValueDict["NZBtitle"], newValueDict["NZBprov"], now()))
custom_notify_snatch(newValueDict["BookID"])
scheduleJob(action='Start', target='processDir')
return True + True # we found it
else:

View File

@ -30,7 +30,7 @@ import lazylibrarian
from lazylibrarian import logger, database, utorrent, transmission, qbittorrent, deluge, rtorrent, synology, bencode
from lazylibrarian.common import scheduleJob, USER_AGENT, setperm, internet
from lazylibrarian.formatter import plural, unaccented_str, replace_all, getList, check_int, now, cleanName
from lazylibrarian.notifiers import notify_snatch
from lazylibrarian.notifiers import notify_snatch, custom_notify_snatch
from lazylibrarian.providers import IterateOverTorrentSites
from lib.deluge_client import DelugeRPCClient
from lib.fuzzywuzzy import fuzz
@ -239,6 +239,7 @@ def processResultList(resultlist, book, searchtype):
logger.info('Downloading %s from %s' % (newValueDict["NZBtitle"], newValueDict["NZBprov"]))
notify_snatch("%s from %s at %s" %
(newValueDict["NZBtitle"], newValueDict["NZBprov"], now()))
custom_notify_snatch(newValueDict["BookID"])
scheduleJob(action='Start', target='processDir')
return True + True # we found it
else:

View File

@ -39,7 +39,7 @@ from lazylibrarian.gr import GoodReads
from lazylibrarian.importer import addAuthorToDB, addAuthorNameToDB, update_totals, search_for
from lazylibrarian.librarysync import LibraryScan
from lazylibrarian.manualbook import searchItem
from lazylibrarian.notifiers import notify_snatch
from lazylibrarian.notifiers import notify_snatch, custom_notify_snatch
from lazylibrarian.postprocess import processAlternate, processDir
from lazylibrarian.searchmag import search_magazines
from lazylibrarian.searchnzb import search_nzb_book, NZBDownloadMethod
@ -544,6 +544,7 @@ class WebInterface(object):
if snatch:
logger.info('Downloading %s from %s' % (bookdata["BookName"], provider))
notify_snatch("%s from %s at %s" % (unaccented(bookdata["BookName"]), provider, now()))
custom_notify_snatch(bookid)
scheduleJob(action='Start', target='processDir')
raise cherrypy.HTTPRedirect("authorPage?AuthorID=%s" % AuthorID)
else:
@ -1414,6 +1415,7 @@ class WebInterface(object):
if snatch: # if snatch fails, downloadmethods already report it
logger.info('Downloading %s from %s' % (items['nzbtitle'], items['nzbprov']))
notifiers.notify_snatch(items['nzbtitle'] + ' at ' + now())
custom_notify_snatch(items['bookid'])
scheduleJob(action='Start', target='processDir')
raise cherrypy.HTTPRedirect("pastIssues")