From 68d662e689cd42687341c550fb6ebb74e6968d21 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Mon, 8 Sep 2014 00:29:57 +0200 Subject: module -> pyload --- pyload/plugins/hooks/WindowsPhoneToastNotify.py | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 pyload/plugins/hooks/WindowsPhoneToastNotify.py (limited to 'pyload/plugins/hooks/WindowsPhoneToastNotify.py') diff --git a/pyload/plugins/hooks/WindowsPhoneToastNotify.py b/pyload/plugins/hooks/WindowsPhoneToastNotify.py new file mode 100644 index 000000000..79812cefa --- /dev/null +++ b/pyload/plugins/hooks/WindowsPhoneToastNotify.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- + +import httplib +import time + +from pyload.plugins.Hook import Hook + + +class WindowsPhoneToastNotify(Hook): + __name__ = "WindowsPhoneToastNotify" + __type__ = "hook" + __version__ = "0.02" + + __config__ = [("activated", "bool", "Activated", False), + ("force", "bool", "Force even if client is connected", False), + ("pushId", "str", "pushId", ""), + ("pushUrl", "str", "pushUrl", ""), + ("pushTimeout", "int", "Timeout between notifications in seconds", 0)] + + __description__ = """Send push notifications to Windows Phone""" + __author_name__ = "Andy Voigt" + __author_mail__ = "phone-support@hotmail.de" + + + def setup(self): + self.info = {} + + def getXmlData(self): + myxml = (" " + " Pyload Mobile Captcha waiting! " + " ") + return myxml + + def doRequest(self): + URL = self.getConfig("pushUrl") + request = self.getXmlData() + webservice = httplib.HTTP(URL) + webservice.putrequest("POST", self.getConfig("pushId")) + webservice.putheader("Host", URL) + webservice.putheader("Content-type", "text/xml") + webservice.putheader("X-NotificationClass", "2") + webservice.putheader("X-WindowsPhone-Target", "toast") + webservice.putheader("Content-length", "%d" % len(request)) + webservice.endheaders() + webservice.send(request) + webservice.close() + self.setStorage("LAST_NOTIFY", time.time()) + + def newCaptchaTask(self, task): + if not self.getConfig("pushId") or not self.getConfig("pushUrl"): + return False + + if self.core.isClientConnected() and not self.getConfig("force"): + return False + + if (time.time() - float(self.getStorage("LAST_NOTIFY", 0))) < self.getConf("pushTimeout"): + return False + + self.doRequest() -- cgit v1.2.3