summaryrefslogtreecommitdiffstats
path: root/module/plugins/hooks/WindowsPhoneNotify.py
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2015-03-08 23:32:11 +0100
committerGravatar Walter Purcaro <vuolter@gmail.com> 2015-03-08 23:32:11 +0100
commitdb330ae85f9de5a9a19c7141c1a2d6877e02e7da (patch)
tree918d85a26aa77a94a34586d2351a2563cccb9392 /module/plugins/hooks/WindowsPhoneNotify.py
parent[ZippyshareCom] Better lib import (diff)
downloadpyload-db330ae85f9de5a9a19c7141c1a2d6877e02e7da.tar.xz
Update notify addon
Diffstat (limited to 'module/plugins/hooks/WindowsPhoneNotify.py')
-rw-r--r--module/plugins/hooks/WindowsPhoneNotify.py52
1 files changed, 32 insertions, 20 deletions
diff --git a/module/plugins/hooks/WindowsPhoneNotify.py b/module/plugins/hooks/WindowsPhoneNotify.py
index e0dd75f92..010198bf1 100644
--- a/module/plugins/hooks/WindowsPhoneNotify.py
+++ b/module/plugins/hooks/WindowsPhoneNotify.py
@@ -1,29 +1,29 @@
# -*- coding: utf-8 -*-
import httplib
+import time
-from time import time
-
-from module.plugins.Hook import Hook
+from module.plugins.Hook import Hook, Expose
class WindowsPhoneNotify(Hook):
__name__ = "WindowsPhoneNotify"
__type__ = "hook"
- __version__ = "0.07"
+ __version__ = "0.08"
__config__ = [("id" , "str" , "Push ID" , "" ),
("url" , "str" , "Push url" , "" ),
("notifycaptcha" , "bool", "Notify captcha request" , True ),
("notifypackage" , "bool", "Notify package finished" , True ),
- ("notifyprocessed", "bool", "Notify processed packages status" , True ),
- ("timeout" , "int" , "Timeout between captchas in seconds" , 5 ),
- ("force" , "bool", "Send notifications if client is connected", False)]
+ ("notifyprocessed", "bool", "Notify status of processed packages" , True ),
+ ("sendtimewait" , "int" , "Timewait in seconds between notifications", 5 ),
+ ("sendpermin" , "int" , "Max notifications per minute" , 12 ),
+ ("ignoreclient" , "bool", "Send notifications if client is connected", False)]
__description__ = """Send push notifications to Windows Phone"""
__license__ = "GPLv3"
- __authors__ = [("Andy Voigt", "phone-support@hotmail.de"),
- ("Walter Purcaro", "vuolter@gmail.com")]
+ __authors__ = [("Andy Voigt" , "phone-support@hotmail.de"),
+ ("Walter Purcaro", "vuolter@gmail.com" )]
event_list = ["allDownloadsProcessed"]
@@ -35,16 +35,14 @@ class WindowsPhoneNotify(Hook):
def setup(self):
- self.info = {} #@TODO: Remove in 0.4.10
- self.last_notify = 0
+ self.info = {} #@TODO: Remove in 0.4.10
+ self.last_notify = 0
+ self.notifications = 0
def newCaptchaTask(self, task):
if not self.getConfig("notifycaptcha"):
- return False
-
- if time() - self.last_notify < self.getConf("timeout"):
- return False
+ return
self.notify(_("Captcha"), _("New request waiting user input"))
@@ -56,7 +54,7 @@ class WindowsPhoneNotify(Hook):
def allDownloadsProcessed(self):
if not self.getConfig("notifyprocessed"):
- return False
+ return
if any(True for pdata in self.core.api.getQueue() if pdata.linksdone < pdata.linkstotal):
self.notify(_("Package failed"), _("One or more packages was not completed successfully"))
@@ -70,15 +68,28 @@ class WindowsPhoneNotify(Hook):
"</wp:Toast> </wp:Notification>" % msg)
+ @Expose
def notify(self, event, msg=""):
id = self.getConfig("id")
url = self.getConfig("url")
if not id or not url:
- return False
+ return
+
+ if self.core.isClientConnected() and not self.getConfig("ignoreclient"):
+ return
+
+ elapsed_time = time.time() - self.last_notify
+
+ if elapsed_time < self.getConf("sendtimewait"):
+ return
+
+ if elapsed_time > 60:
+ self.notifications = 0
+
+ elif self.notifications >= self.getConf("sendpermin"):
+ return
- if self.core.isClientConnected() and not self.getConfig("force"):
- return False
request = self.getXmlData("%s: %s" % (event, msg) if msg else event)
webservice = httplib.HTTP(url)
@@ -93,4 +104,5 @@ class WindowsPhoneNotify(Hook):
webservice.send(request)
webservice.close()
- self.last_notify = time()
+ self.last_notify = time.time()
+ self.notifications += 1