3
from httplib import HTTPSConnection
4
from urllib import urlencode
6
from flexget.plugin import get_plugin_by_name, register_plugin
8
log = logging.getLogger('prowl')
10
headers = {'User-Agent': "FlexGet Prowl plugin/%s" % str(__version__),
11
'Content-type': "application/x-www-form-urlencoded"}
14
class OutputProwl(object):
18
[application: application name, default FlexGet]
19
[event: event title, default New Release]
20
[priority: -2 - 2 (2 = highest), default 0]
22
Configuration parameters are also supported from entries (eg. through set).
26
from flexget import validator
27
config = validator.factory('dict')
28
config.accept('text', key='apikey', required=True)
29
config.accept('text', key='application')
30
config.accept('text', key='event')
31
config.accept('integer', key='priority')
34
def on_process_start(self, feed):
36
Register the usable set: keywords.
38
set_plugin = get_plugin_by_name('set')
39
set_plugin.instance.register_keys({'apikey': 'text', 'application': 'text', \
40
'event': 'text', 'priority': 'integer'})
42
def get_config(self, feed):
43
config = feed.config.get('prowl', {})
44
if isinstance(config, bool):
45
config = {'enabled': config}
46
config.setdefault('apikey', '')
47
config.setdefault('application', 'FlexGet')
48
config.setdefault('event', 'New release')
49
config.setdefault('priority', 0)
52
def on_feed_output(self, feed):
53
for entry in feed.accepted:
55
if feed.manager.options.test:
56
log.info("Would send prowl message about: %s", entry['title'])
60
config = self.get_config(feed)
61
apikey = entry.get('apikey', config['apikey'])
62
application = entry.get('application', config['application'])
63
event = entry.get('event', config['event'])
64
priority = entry.get('priority', config['priority'])
65
description = entry['title']
68
h = HTTPSConnection('prowl.weks.net')
71
data = {'priority': priority, 'application': application, 'apikey': apikey, \
72
'event': event, 'description': description}
73
h.request("POST", "/publicapi/add", headers=headers, body=urlencode(data))
75
# Check if it succeeded
76
response = h.getresponse()
77
request_status = response.status
79
# error codes and messages from http://prowl.weks.net/api.php
80
if request_status == 200:
81
log.debug("Prowl message sent")
82
elif request_status == 400:
83
log.error("Bad request, the parameters you provided did not validate")
84
elif request_status == 401:
85
log.error("Not authorized, the API key given is not valid, and does not correspond to a user.")
86
elif request_status == 406:
87
log.error("Not acceptable, your IP address has exceeded the API limit.")
88
elif request_status == 500:
89
log.error("Internal server error, something failed to execute properly on the Prowl side.")
91
log.error("Unknown error when sending Prowl message")
93
register_plugin(OutputProwl, 'prowl')