Merge pull request #1 from pyntel/pushover

Pushover functionality
This commit is contained in:
John Machielsen 2013-04-01 07:02:07 -07:00
commit 0b0c224aa4
7 changed files with 198 additions and 49 deletions

23
.gitignore vendored
View File

@ -1,5 +1,20 @@
mylar.db
config.ini
.gitignore
*.pyc
.idea
logs
*.db
*.jpg
*.txt
*.ini
*.csv
*.log
*.1
*.2

View File

@ -591,48 +591,68 @@
</div>
</div>
</fieldset>
<fieldset>
<h3>NotifyMyAndroid</h3>
<div class="checkbox row">
<input type="checkbox" name="nma_enabled" id="nma" value="1" ${config['nma_enabled']} /><label>Enable NotifyMyAndroid</label>
</div>
<div id="nmaoptions">
<div class="row">
<div class="row checkbox">
<input type="checkbox" name="nma_onsnatch" value="1" ${config['nma_onsnatch']} /><label>Notify on snatch?</label>
</div>
<label>NotifyMyAndroid API Key</label>
<input type="text" name="nma_apikey" value="${config['nma_apikey']}" size="30">
<small>Separate multiple api keys with commas</small>
</div>
<div class="row">
<label>Priority</label>
<select name="nma_priority">
%for x in [-2,-1,0,1,2]:
<%
if config['nma_priority'] == x:
nma_priority_selected = 'selected'
else:
nma_priority_selected = ''
if x == -2:
nma_priority_value = 'Very Low'
elif x == -1:
nma_priority_value = 'Moderate'
elif x == 0:
nma_priority_value = 'Normal'
elif x == 1:
nma_priority_value = 'High'
else:
nma_priority_value = 'Emergency'
%>
<option value=${x} ${nma_priority_selected}>${nma_priority_value}</option>
%endfor
</select>
</div>
</div>
</fieldset>
<fieldset>
<h3>NotifyMyAndroid</h3>
<div class="checkbox row">
<input type="checkbox" name="nma_enabled" id="nma" value="1" ${config['nma_enabled']} /><label>Enable NotifyMyAndroid</label>
</div>
<div id="nmaoptions">
<div class="row">
<div class="row checkbox">
<input type="checkbox" name="nma_onsnatch" value="1" ${config['nma_onsnatch']} /><label>Notify on snatch?</label>
</div>
<label>NotifyMyAndroid API Key</label>
<input type="text" name="nma_apikey" value="${config['nma_apikey']}" size="30">
<small>Separate multiple api keys with commas</small>
</div>
<div class="row">
<label>Priority</label>
<select name="nma_priority">
%for x in [-2,-1,0,1,2]:
<%
if config['nma_priority'] == x:
nma_priority_selected = 'selected'
else:
nma_priority_selected = ''
if x == -2:
nma_priority_value = 'Very Low'
elif x == -1:
nma_priority_value = 'Moderate'
elif x == 0:
nma_priority_value = 'Normal'
elif x == 1:
nma_priority_value = 'High'
else:
nma_priority_value = 'Emergency'
%>
<option value=${x} ${nma_priority_selected}>${nma_priority_value}</option>
%endfor
</select>
</div>
</div>
</fieldset>
<fieldset>
<h3>Pushover</h3>
<div class="row checkbox">
<input type="checkbox" name="pushover_enabled" id="pushover" value="1" ${config['pushover_enabled']} /><label>Enable Pushover Notifications</label>
</div>
<div id="pushoveroptions">
<div class="row">
<label>API key</label><input type="text" name="pushover_apikey" value="${config['pushover_apikey']}" size="50">
</div>
<div class="row">
<label>User key</label><input type="text" name="pushover_userkey" value="${config['pushover_userkey']}" size="50">
</div>
<div class="row checkbox">
<input type="checkbox" name="pushover_onsnatch" value="1" ${config['pushover_onsnatch']} /><label>Notify on snatch?</label>
</div>
<div class="row">
<label>Priority (-2,-1,0,1 or 2):</label>
<input type="text" name="pushover_priority" value="${config['pushover_priority']}" size="2">
</div>
</div>
</fieldset>
</td>
</tr>
@ -713,6 +733,25 @@
}
});
if ($("#pushover").is(":checked"))
{
$("#pushoveroptions").show();
}
else
{
$("#pushoveroptions").hide();
}
$("#pushover").click(function(){
if ($("#pushover").is(":checked"))
{
$("#pushoveroptions").slideDown();
}
else
{
$("#pushoveroptions").slideUp();
}
});
var deletedNewznabs = 0;

View File

@ -404,6 +404,12 @@ class PostProcessor(object):
nma = notifiers.NMA()
nma.notify(series, str(issueyear), str(issuenum))
if mylar.PUSHOVER_ENABLED:
pushmessage = series + '(' + issueyear + ') - issue #' + issuenum
logger.info(u"Pushover request")
pushover = notifiers.PUSHOVER()
pushover.notify(pushmessage,"Download and Postprocessing completed")
# retrieve/create the corresponding comic objects
if mylar.ENABLE_EXTRA_SCRIPTS:

View File

@ -131,6 +131,11 @@ NMA_ENABLED = False
NMA_APIKEY = None
NMA_PRIORITY = None
NMA_ONSNATCH = None
PUSHOVER_ENABLED = True
PUSHOVER_PRIORITY = 1
PUSHOVER_APIKEY = None
PUSHOVER_USERKEY = None
PUSHOVER_ONSNATCH = True
SKIPPED2WANTED = False
CVINFO = False
LOG_LEVEL = None
@ -252,7 +257,7 @@ def initialize():
USE_NZBGET, NZBGET_HOST, NZBGET_PORT, NZBGET_USERNAME, NZBGET_PASSWORD, NZBGET_CATEGORY, NZBGET_PRIORITY, NZBSU, NZBSU_APIKEY, DOGNZB, DOGNZB_APIKEY, NZBX,\
NEWZNAB, NEWZNAB_HOST, NEWZNAB_APIKEY, NEWZNAB_ENABLED, EXTRA_NEWZNABS,\
RAW, RAW_PROVIDER, RAW_USERNAME, RAW_PASSWORD, RAW_GROUPS, EXPERIMENTAL, \
PROWL_ENABLED, PROWL_PRIORITY, PROWL_KEYS, PROWL_ONSNATCH, NMA_ENABLED, NMA_APIKEY, NMA_PRIORITY, NMA_ONSNATCH, \
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, \
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, \
COMIC_LOCATION, QUAL_ALTVERS, QUAL_SCANNER, QUAL_TYPE, QUAL_QUALITY, ENABLE_EXTRA_SCRIPTS, EXTRA_SCRIPTS, ENABLE_PRE_SCRIPTS, PRE_SCRIPTS, PULLNEW, COUNT_ISSUES, COUNT_HAVES, COUNT_COMICS, SYNO_FIX, ANNUALS_ON
@ -335,6 +340,12 @@ def initialize():
NMA_PRIORITY = check_setting_int(CFG, 'NMA', 'nma_priority', 0)
NMA_ONSNATCH = bool(check_setting_int(CFG, 'NMA', 'nma_onsnatch', 0))
PUSHOVER_ENABLED = bool(check_setting_int(CFG, 'PUSHOVER', 'pushover_enabled', 0))
PUSHOVER_APIKEY = check_setting_str(CFG, 'PUSHOVER', 'pushover_apikey', '')
PUSHOVER_USERKEY = check_setting_str(CFG, 'PUSHOVER', 'pushover_userkey', '')
PUSHOVER_PRIORITY = check_setting_int(CFG, 'PUSHOVER', 'pushover_priority', 0)
PUSHOVER_ONSNATCH = bool(check_setting_int(CFG, 'PUSHOVER', 'pushover_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))
@ -717,6 +728,13 @@ def config_write():
new_config['NMA']['nma_priority'] = NMA_PRIORITY
new_config['NMA']['nma_onsnatch'] = int(NMA_ONSNATCH)
new_config['PUSHOVER'] = {}
new_config['PUSHOVER']['pushover_enabled'] = int(PUSHOVER_ENABLED)
new_config['PUSHOVER']['pushover_apikey'] = PUSHOVER_APIKEY
new_config['PUSHOVER']['pushover_userkey'] = PUSHOVER_USERKEY
new_config['PUSHOVER']['pushover_priority'] = PUSHOVER_PRIORITY
new_config['PUSHOVER']['pushover_onsnatch'] = int(PUSHOVER_ONSNATCH)
new_config['Raw'] = {}
new_config['Raw']['raw'] = int(RAW)
new_config['Raw']['raw_provider'] = RAW_PROVIDER

View File

@ -126,3 +126,61 @@ class NMA:
if not request:
logger.warn('Error sending notification request to NotifyMyAndroid')
# 2013-04-01 Added Pushover.net notifications, based on copy of Prowl class above.
# No extra care has been put into API friendliness at the moment (read: https://pushover.net/api#friendly)
class PUSHOVER:
def __init__(self):
self.enabled = mylar.PUSHOVER_ENABLED
self.apikey = mylar.PUSHOVER_APIKEY
self.userkey = mylar.PUSHOVER_USERKEY
self.priority = mylar.PUSHOVER_PRIORITY
# other API options:
# self.device_id = mylar.PUSHOVER_DEVICE_ID
# device - option for specifying which of your registered devices Mylar should send to. No option given, it sends to all devices on Pushover (default)
# URL / URL_TITLE (both for use with the COPS/OPDS server I'm building maybe?)
# Sound - name of soundfile to override default sound choice
# not sure if this is needed for Pushover
#def conf(self, options):
# return cherrypy.config['config'].get('Pushover', options)
def notify(self, message, event):
if not mylar.PUSHOVER_ENABLED:
return
http_handler = HTTPSConnection("api.pushover.net:443")
data = {'token': mylar.PUSHOVER_APIKEY,
'user': mylar.PUSHOVER_USERKEY,
'message': message.encode("utf-8"),
'title': event,
'priority': mylar.PUSHOVER_PRIORITY }
http_handler.request("POST",
"/1/messages.json",
body = urlencode(data),
headers = {'Content-type': "application/x-www-form-urlencoded"}
)
response = http_handler.getresponse()
request_status = response.status
if request_status == 200:
logger.info(u"Pushover notifications sent.")
return True
elif request_status == 401:
logger.info(u"Pushover auth failed: %s" % response.reason)
return False
else:
logger.info(u"Pushover notification failed.")
return False
def test(self, apikey, userkey, priority):
self.enabled = True
self.apikey = apikey
self.userkey = userkey
self.priority = priority
self.notify('ZOMG Lazors Pewpewpew!', 'Test Message')

View File

@ -823,7 +823,10 @@ def NZB_SEARCH(ComicName, IssueNumber, ComicYear, SeriesYear, nzbprov, nzbpr, Is
logger.info(u"Sending NMA notification")
nma = notifiers.NMA()
nma.notify(snatched_nzb=nzbname)
if mylar.PUSHOVER_ENABLED and mylar.PUSHOVER_ONSNATCH:
logger.info(u"Sending Pushover notification")
pushover = notifiers.PUSHOVER()
pushover.notify(nzbname,"Download started")
foundc = "yes"
done = True

View File

@ -1255,6 +1255,11 @@ class WebInterface(object):
"nma_apikey": mylar.NMA_APIKEY,
"nma_priority": int(mylar.NMA_PRIORITY),
"nma_onsnatch": helpers.checked(mylar.NMA_ONSNATCH),
"pushover_enabled": helpers.checked(mylar.PUSHOVER_ENABLED),
"pushover_onsnatch": helpers.checked(mylar.PUSHOVER_ONSNATCH),
"pushover_apikey": mylar.PUSHOVER_APIKEY,
"pushover_userkey": mylar.PUSHOVER_USERKEY,
"pushover_priority": mylar.PUSHOVER_PRIORITY,
"enable_extra_scripts" : helpers.checked(mylar.ENABLE_EXTRA_SCRIPTS),
"extra_scripts" : mylar.EXTRA_SCRIPTS,
"post_processing" : helpers.checked(mylar.POST_PROCESSING),
@ -1378,7 +1383,7 @@ class WebInterface(object):
use_nzbget=0, nzbget_host=None, nzbget_port=None, nzbget_username=None, nzbget_password=None, nzbget_category=None, nzbget_priority=None,
usenet_retention=None, nzbsu=0, nzbsu_apikey=None, dognzb=0, dognzb_apikey=None, nzbx=0, newznab=0, newznab_host=None, newznab_apikey=None, newznab_enabled=0,
raw=0, raw_provider=None, raw_username=None, raw_password=None, raw_groups=None, experimental=0,
prowl_enabled=0, prowl_onsnatch=0, prowl_keys=None, prowl_priority=None, nma_enabled=0, nma_apikey=None, nma_priority=0, nma_onsnatch=0,
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,
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, syno_fix=0,
destination_dir=None, 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, **kwargs):
mylar.HTTP_HOST = http_host
@ -1443,6 +1448,11 @@ class WebInterface(object):
mylar.NMA_APIKEY = nma_apikey
mylar.NMA_PRIORITY = nma_priority
mylar.NMA_ONSNATCH = nma_onsnatch
mylar.PUSHOVER_ENABLED = pushover_enabled
mylar.PUSHOVER_APIKEY = pushover_apikey
mylar.PUSHOVER_USERKEY = pushover_userkey
mylar.PUSHOVER_PRIORITY = pushover_priority
mylar.PUSHOVER_ONSNATCH = pushover_onsnatch
mylar.USE_MINSIZE = use_minsize
mylar.MINSIZE = minsize
mylar.USE_MAXSIZE = use_maxsize