Add telegram notifier

This commit is contained in:
Bart274 2016-11-08 09:11:51 +01:00 committed by evilhero
parent a3d7d38526
commit 4a3146fd27
6 changed files with 73 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

@ -1964,6 +1964,10 @@ class PostProcessor(object):
pushbullet = notifiers.PUSHBULLET()
pushbullet.notify(prline=prline, prline2=prline2, module=module)
if mylar.TELEGRAM_ENABLED:
telegram = notifiers.TELEGRAM()
telegram.notify(prline, prline2)
logger.info(module + ' Post-Processing completed for: ' + series + ' ' + dispiss)
self._log(u"Post Processing SUCCESSFUL! ")

View File

@ -223,6 +223,10 @@ PUSHBULLET_ENABLED = False
PUSHBULLET_APIKEY = None
PUSHBULLET_DEVICEID = None
PUSHBULLET_ONSNATCH = False
TELEGRAM_ENABLED = False
TELEGRAM_TOKEN = None
TELEGRAM_USERID = None
TELEGRAM_ONSNATCH = False
SKIPPED2WANTED = False
CVINFO = False
@ -477,7 +481,8 @@ def initialize():
PROWL_ENABLED, PROWL_PRIORITY, PROWL_KEYS, PROWL_ONSNATCH, NMA_ENABLED, NMA_APIKEY, NMA_PRIORITY, NMA_ONSNATCH, PUSHOVER_ENABLED, PUSHOVER_PRIORITY, PUSHOVER_APIKEY, PUSHOVER_USERKEY, PUSHOVER_ONSNATCH, BOXCAR_ENABLED, BOXCAR_ONSNATCH, BOXCAR_TOKEN, \
PUSHBULLET_ENABLED, PUSHBULLET_APIKEY, PUSHBULLET_DEVICEID, PUSHBULLET_ONSNATCH, LOCMOVE, NEWCOM_DIR, FFTONEWCOM_DIR, \
PREFERRED_QUALITY, MOVE_FILES, RENAME_FILES, LOWERCASE_FILENAMES, USE_MINSIZE, MINSIZE, USE_MAXSIZE, MAXSIZE, CORRECT_METADATA, FOLDER_FORMAT, FILE_FORMAT, REPLACE_CHAR, REPLACE_SPACES, ADD_TO_CSV, CVINFO, LOG_LEVEL, POST_PROCESSING, POST_PROCESSING_SCRIPT, FILE_OPTS, SEARCH_DELAY, GRABBAG_DIR, READ2FILENAME, SEND2READ, TAB_ENABLE, TAB_HOST, TAB_USER, TAB_PASS, TAB_DIRECTORY, STORYARCDIR, COPY2ARCDIR, CVURL, CHECK_FOLDER, ENABLE_CHECK_FOLDER, \
COMIC_LOCATION, QUAL_ALTVERS, QUAL_SCANNER, QUAL_TYPE, QUAL_QUALITY, ENABLE_EXTRA_SCRIPTS, EXTRA_SCRIPTS, ENABLE_PRE_SCRIPTS, PRE_SCRIPTS, PULLNEW, ALT_PULL, PULLBYFILE, COUNT_ISSUES, COUNT_HAVES, COUNT_COMICS, SYNO_FIX, ENFORCE_PERMS, CHMOD_FILE, CHMOD_DIR, CHOWNER, CHGROUP, ANNUALS_ON, CV_ONLY, CV_ONETIMER, CURRENT_WEEKNUMBER, CURRENT_YEAR, PULL_REFRESH, WEEKFOLDER, WEEKFOLDER_LOC, UMASK
COMIC_LOCATION, QUAL_ALTVERS, QUAL_SCANNER, QUAL_TYPE, QUAL_QUALITY, ENABLE_EXTRA_SCRIPTS, EXTRA_SCRIPTS, ENABLE_PRE_SCRIPTS, PRE_SCRIPTS, PULLNEW, ALT_PULL, PULLBYFILE, COUNT_ISSUES, COUNT_HAVES, COUNT_COMICS, SYNO_FIX, ENFORCE_PERMS, CHMOD_FILE, CHMOD_DIR, CHOWNER, CHGROUP, ANNUALS_ON, CV_ONLY, CV_ONETIMER, CURRENT_WEEKNUMBER, CURRENT_YEAR, PULL_REFRESH, WEEKFOLDER, WEEKFOLDER_LOC, UMASK,
TELEGRAM_ENABLED, TELEGRAM_TOKEN, TELEGRAM_USERID
if __INITIALIZED__:
return False
@ -645,6 +650,11 @@ def initialize():
PUSHBULLET_DEVICEID = check_setting_str(CFG, 'PUSHBULLET', 'pushbullet_deviceid', '')
PUSHBULLET_ONSNATCH = bool(check_setting_int(CFG, 'PUSHBULLET', 'pushbullet_onsnatch', 0))
TELEGRAM_ENABLED = bool(check_setting_int(CFG, 'TELEGRAM', 'telegram_enabled', 0))
TELEGRAM_TOKEN = check_setting_str(CFG, 'TELEGRAM', 'telegram_token', '')
TELEGRAM_USERID = check_setting_str(CFG, 'TELEGRAM', 'telegram_userid', '')
TELEGRAM_ONSNATCH = bool(check_setting_int(CFG, 'TELEGRAM', 'telegram_onsnatch', 0))
USE_MINSIZE = bool(check_setting_int(CFG, 'General', 'use_minsize', 0))
MINSIZE = check_setting_str(CFG, 'General', 'minsize', '')
USE_MAXSIZE = bool(check_setting_int(CFG, 'General', 'use_maxsize', 0))
@ -1593,6 +1603,12 @@ def config_write():
new_config['PUSHBULLET']['pushbullet_deviceid'] = PUSHBULLET_DEVICEID
new_config['PUSHBULLET']['pushbullet_onsnatch'] = int(PUSHBULLET_ONSNATCH)
new_config['TELEGRAM'] = {}
new_config['TELEGRAM']['telegram_enabled'] = int(TELEGRAM_ENABLED)
new_config['TELEGRAM']['telegram_token'] = TELEGRAM_TOKEN
new_config['TELEGRAM']['telegram_userid'] = TELEGRAM_USERID
new_config['TELEGRAM']['telegram_onsnatch'] = int(TELEGRAM_ONSNATCH)
new_config.write()
def start():

View File

@ -331,3 +331,33 @@ class PUSHBULLET:
def test_notify(self):
return self.notify(prline='Test Message', prline2='Release the Ninjas!')
class TELEGRAM:
def __init__(self):
self.token = mylar.TELEGRAM_TOKEN
self.userid = mylar.TELEGRAM_USERID
self.TELEGRAM_API = "https://api.telegram.org/bot%s/%s"
def notify(self, message, status):
if not mylar.TELEGRAM_ENABLED:
return
# Construct message
payload = {'chat_id': self.userid, 'text': status + ': ' + message}
# Send message to user using Telegram's Bot API
try:
response = requests.post(self.TELEGRAM_API % (self.token, "sendMessage"), data=payload)
except Exception, e:
logger.info(u'Telegram notify failed: ' + str(e))
# Error logging
sent_successfuly = True
if not response.status_code == 200:
logger.info(u'Could not send notification to TelegramBot (token=%s). Response: [%s]', (self.token, response.text))
sent_successfuly = False
logger.info(u"Telegram notifications sent.")
return sent_successfuly
def test_notify(self):
return self.notify('Test Message', 'Release the Ninjas!')

View File

@ -2390,6 +2390,10 @@ def notify_snatch(nzbname, sent_to, modcomicname, comyear, IssueNumber, nzbprov)
logger.info(u"Sending Pushbullet notification")
pushbullet = notifiers.PUSHBULLET()
pushbullet.notify(snline=snline, snatched=nzbname, sent_to=sent_to, prov=nzbprov, method='POST')
if mylar.TELEGRAM_ENABLED and mylar.TELEGRAM_ONSNATCH:
logger.info(u"Sending Telegram notification")
telegram = notifiers.TELEGRAM()
telegram.notify(snline, nzbname)
return

View File

@ -4004,6 +4004,10 @@ class WebInterface(object):
"pushbullet_onsnatch": helpers.checked(mylar.PUSHBULLET_ONSNATCH),
"pushbullet_apikey": mylar.PUSHBULLET_APIKEY,
"pushbullet_deviceid": mylar.PUSHBULLET_DEVICEID,
"telegram_enabled": helpers.checked(mylar.TELEGRAM_ENABLED),
"telegram_onsnatch": helpers.checked(mylar.TELEGRAM_ONSNATCH),
"telegram_token": mylar.TELEGRAM_TOKEN,
"telegram_userid": mylar.TELEGRAM_USERID,
"enable_extra_scripts": helpers.checked(mylar.ENABLE_EXTRA_SCRIPTS),
"extra_scripts": mylar.EXTRA_SCRIPTS,
"post_processing": helpers.checked(mylar.POST_PROCESSING),
@ -4239,7 +4243,7 @@ class WebInterface(object):
enable_meta=0, cbr2cbz_only=0, cmtagger_path=None, ct_tag_cr=0, ct_tag_cbl=0, ct_cbz_overwrite=0, unrar_cmd=None, enable_rss=0, rss_checkinterval=None, failed_download_handling=0, failed_auto=0, enable_torrent_search=0, enable_tpse=0, enable_32p=0, mode_32p=0, rssfeed_32p=None, passkey_32p=None, username_32p=None, password_32p=None, snatchedtorrent_notify=0,
enable_torrents=0, minseeds=0, local_watchdir=None, seedbox_watchdir=None, seedbox_user=None, seedbox_pass=None, seedbox_host=None, seedbox_port=None,
prowl_enabled=0, prowl_onsnatch=0, prowl_keys=None, prowl_priority=None, nma_enabled=0, nma_apikey=None, nma_priority=0, nma_onsnatch=0, pushover_enabled=0, pushover_onsnatch=0, pushover_apikey=None, pushover_userkey=None, pushover_priority=None, boxcar_enabled=0, boxcar_onsnatch=0, boxcar_token=None,
pushbullet_enabled=0, pushbullet_apikey=None, pushbullet_deviceid=None, pushbullet_onsnatch=0, torrent_downloader=0, torrent_local=0, torrent_seedbox=0, utorrent_host=None, utorrent_username=None, utorrent_password=None, utorrent_label=None,
pushbullet_enabled=0, pushbullet_apikey=None, pushbullet_deviceid=None, pushbullet_onsnatch=0, telegram_enabled=0, telegram_token=None, telegram_userid=None, telegram_onsnatch=0, torrent_downloader=0, torrent_local=0, torrent_seedbox=0, utorrent_host=None, utorrent_username=None, utorrent_password=None, utorrent_label=None,
rtorrent_host=None, rtorrent_username=None, rtorrent_password=None, rtorrent_directory=None, rtorrent_label=None, rtorrent_startonload=0, transmission_host=None, transmission_username=None, transmission_password=None, transmission_directory=None,
preferred_quality=0, move_files=0, rename_files=0, add_to_csv=1, cvinfo=0, lowercase_filenames=0, folder_format=None, file_format=None, enable_extra_scripts=0, extra_scripts=None, enable_pre_scripts=0, pre_scripts=None, post_processing=0, file_opts=None, syno_fix=0, search_delay=None, enforce_perms=1, chmod_dir=0777, chmod_file=0660, chowner=None, chgroup=None,
tsab=None, destination_dir=None, create_folders=1, replace_spaces=0, replace_char=None, use_minsize=0, minsize=None, use_maxsize=0, maxsize=None, autowant_all=0, autowant_upcoming=0, comic_cover_local=0, zero_level=0, zero_level_n=None, interface=None, dupeconstraint=None, ddump=0, duplicate_dump=None, **kwargs):
@ -4368,6 +4372,10 @@ class WebInterface(object):
mylar.PUSHBULLET_APIKEY = pushbullet_apikey
mylar.PUSHBULLET_DEVICEID = pushbullet_deviceid
mylar.PUSHBULLET_ONSNATCH = pushbullet_onsnatch
mylar.TELEGRAM_ENABLED = telegram_enabled
mylar.TELEGRAM_TOKEN = telegram_token
mylar.TELEGRAM_USERID = telegram_userid
mylar.TELEGRAM_ONSNATCH = telegram_onsnatch
mylar.USE_MINSIZE = use_minsize
mylar.MINSIZE = minsize
mylar.USE_MAXSIZE = use_maxsize
@ -4908,6 +4916,15 @@ class WebInterface(object):
return "Error sending test message to Pushbullet"
testpushbullet.exposed = True
def testtelegram(self):
telegram = notifiers.TELEGRAM()
result = telegram.test_notify()
if result == True:
return "Successfully sent Telegram test - check to make sure it worked"
else:
return "Error sending test message to Telegram"
testtelegram.exposed = True
def orderThis(self, **kwargs):
logger.info('here')
return