Skip to content

Commit

Permalink
Reworked debug messages
Browse files Browse the repository at this point in the history
  • Loading branch information
philborman committed Jul 6, 2017
1 parent e4414bb commit 33c6e72
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lazylibrarian/notifiers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def notify_download(title, bookid=None):
try:
for n in notifiers:
if n == 'email_notifier':
n.notify_download(title, bookid)
n.notify_download(title, bookid=bookid)
else:
n.notify_download(title)
except Exception as e:
Expand Down
50 changes: 24 additions & 26 deletions lazylibrarian/notifiers/email_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,31 +108,30 @@ def notify_download(self, title, bookid=None, force=False):
if lazylibrarian.CONFIG['EMAIL_NOTIFY_ONDOWNLOAD']:
files = None
event = notifyStrings[NOTIFY_DOWNLOAD]
if lazylibrarian.CONFIG['EMAIL_SENDFILE_ONDOWNLOAD'] and not bookid:
logger.debug('Requested to attach book, but no bookid')
elif bookid:
myDB = database.DBConnection()
data = myDB.match('SELECT BookFile,BookName from books where BookID=?', (bookid,))
try:
if not data:
logger.debug('Email send attachment is %s' % lazylibrarian.CONFIG['EMAIL_SENDFILE_ONDOWNLOAD'])
if lazylibrarian.CONFIG['EMAIL_SENDFILE_ONDOWNLOAD']:
if not bookid:
logger.debug('Email request to attach book, but no bookid')
else:
myDB = database.DBConnection()
data = myDB.match('SELECT BookFile,BookName from books where BookID=?', (bookid,))
if data:
filename = data['BookFile']
title = data['BookName']
logger.debug('Found %s for bookid %s' % (filename, bookid))
else:
logger.debug('[%s] is not a valid bookid' % bookid)
filename = data['BookFile']
title = data['BookName']
logger.debug('Found %s for bookid %s' % (filename, bookid))
except Exception:
data = myDB.match('SELECT IssueFile,Title,IssueDate from issues where IssueID=?', (bookid,))
try:
if not data:
logger.debug('[%s] is not a valid issueid' % bookid)
filename = data['IssueFile']
title = "%s - %s" % (data['Title'], data['IssueDate'])
logger.debug('Found %s for issueid %s' % (filename, bookid))
except Exception:
logger.debug("No attachment found for [%s]" % bookid)
filename = ''
if filename:
files = [filename] # could add cover_image, opf
event = "LazyLibrarian Download"
data = myDB.match('SELECT IssueFile,Title,IssueDate from issues where IssueID=?', (bookid,))
if data:
filename = data['IssueFile']
title = "%s - %s" % (data['Title'], data['IssueDate'])
logger.debug('Found %s for issueid %s' % (filename, bookid))
else:
logger.debug('[%s] is not a valid bookid/issueid' % bookid)
filename = ''
if filename:
files = [filename] # could add cover_image, opf
event = "LazyLibrarian Download"
return self._notify(message=title, event=event, force=force, files=files)
return False

Expand All @@ -143,7 +142,6 @@ def test_notify(self, title='Test'):
data = myDB.match('SELECT bookid from books where bookfile <> ""')
if data:
return self.notify_download(title=message, bookid=data['bookid'], force=True)

return self._notify(message=message, event=title, force=True)
return self.notify_download(title=message, bookid=None, force=True)

notifier = EmailNotifier

0 comments on commit 33c6e72

Please sign in to comment.