send imageurl to notifiers

This commit is contained in:
Bart274 2020-01-31 14:13:44 +01:00 committed by evilhero
parent 7df84f51ac
commit d96265d008
No known key found for this signature in database
GPG Key ID: 3E12C51E39D91142
2 changed files with 30 additions and 12 deletions

View File

@ -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()

View File

@ -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