oe2.2 only: add new plugin copy epg via ftp
[enigma2-plugins.git] / growlee / src / Prowl.py
1 from twisted.web.client import getPage
2 from twisted.internet.defer import Deferred
3 from twisted.internet import reactor
4 try:
5         from urllib import urlencode
6 except ImportError as ie:
7         from urllib.parse import urlencode
8
9 from GrowleeConnection import emergencyDisable
10 from . import NOTIFICATIONID
11
12 class ProwlAPI:
13         def __init__(self, host):
14                 self.enable_outgoing = host.enable_outgoing.value
15                 self.api_key = host.password.value
16
17         def sendNotification(self, title='No title.', description='No message.', priority=0, timeout=-1):
18                 if not self.enable_outgoing:
19                         return
20
21                 headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'}
22                 data = {
23                         'apikey': self.api_key,
24                         'application': "growlee",
25                         'event': title,
26                         'description': description,
27                         'priority': priority,
28                 }
29
30                 getPage('https://prowl.weks.net/publicapi/add/', method = 'POST', headers = headers, postdata = urlencode(data)).addErrback(emergencyDisable)
31
32         def stop(self):
33                 defer = Deferred()
34                 reactor.callLater(1, defer.callback, True)
35                 return defer
36