From d96265d008c991375d520e3dfea77ded7b05d5d0 Mon Sep 17 00:00:00 2001 From: Bart274 Date: Fri, 31 Jan 2020 14:13:44 +0100 Subject: [PATCH] send imageurl to notifiers --- mylar/PostProcessor.py | 16 ++++++++++++---- mylar/notifiers.py | 26 ++++++++++++++++++-------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/mylar/PostProcessor.py b/mylar/PostProcessor.py index a0b29ac9..acc99bb4 100755 --- a/mylar/PostProcessor.py +++ b/mylar/PostProcessor.py @@ -1942,8 +1942,12 @@ class PostProcessor(object): logger.info('%s Post-Processing completed for: [ %s #%s ] %s' % (module, comicname, issuenumber, grab_dst)) self._log(u"Post Processing SUCCESSFUL! ") + imageUrl = myDB.select('SELECT ImageURL from issues WHERE IssueID=?', [issueid]) + if imageUrl: + imageUrl = imageUrl[0][0] + try: - self.sendnotify(comicname, issueyear=None, issuenumOG=issuenumber, annchk=annchk, module=module) + self.sendnotify(comicname, issueyear=None, issuenumOG=issuenumber, annchk=annchk, module=module, imageUrl=imageUrl) except: pass @@ -2771,7 +2775,11 @@ class PostProcessor(object): # self.sendnotify(series, issueyear, dispiss, annchk, module) # return self.queue.put(self.valreturn) - self.sendnotify(series, issueyear, dispiss, annchk, module) + imageUrl = myDB.select('SELECT ImageURL from issues WHERE IssueID=?', [issueid]) + if imageUrl: + imageUrl = imageUrl[0][0] + + self.sendnotify(series, issueyear, dispiss, annchk, module, imageUrl) logger.info('%s Post-Processing completed for: %s %s' % (module, series, dispiss)) self._log(u"Post Processing SUCCESSFUL! ") @@ -2784,7 +2792,7 @@ class PostProcessor(object): return self.queue.put(self.valreturn) - def sendnotify(self, series, issueyear, issuenumOG, annchk, module): + def sendnotify(self, series, issueyear, issuenumOG, annchk, module, imageUrl): if issueyear is None: prline = '%s %s' % (series, issuenumOG) @@ -2812,7 +2820,7 @@ class PostProcessor(object): if mylar.CONFIG.TELEGRAM_ENABLED: telegram = notifiers.TELEGRAM() - telegram.notify(prline2) + telegram.notify(prline2, imageUrl) if mylar.CONFIG.SLACK_ENABLED: slack = notifiers.SLACK() diff --git a/mylar/notifiers.py b/mylar/notifiers.py index 663c2a5b..b7d81f5f 100644 --- a/mylar/notifiers.py +++ b/mylar/notifiers.py @@ -340,15 +340,25 @@ class TELEGRAM: else: self.token = test_token - def notify(self, message): - # Construct message - payload = {'chat_id': self.userid, 'text': message} + def notify(self, message, imageurl=None): + if imageurl: + # Construct message + payload = {'chat_id': self.userid, 'caption': message, 'photo': imageurl} - # Send message to user using Telegram's Bot API - try: - response = requests.post(self.TELEGRAM_API % (self.token, "sendMessage"), json=payload, verify=True) - except Exception, e: - logger.info(u'Telegram notify failed: ' + str(e)) + # Send message to user using Telegram's Bot API + try: + response = requests.post(self.TELEGRAM_API % (self.token, "sendPhoto"), json=payload, verify=True) + except Exception, e: + logger.info(u'Telegram notify failed: ' + str(e)) + else: + # Construct message + payload = {'chat_id': self.userid, 'text': message} + + # Send message to user using Telegram's Bot API + try: + response = requests.post(self.TELEGRAM_API % (self.token, "sendMessage"), json=payload, verify=True) + except Exception, e: + logger.info(u'Telegram notify failed: ' + str(e)) # Error logging sent_successfuly = True