summaryrefslogtreecommitdiffstats
path: root/module/plugins/addon/WindowsPhoneToastNotify.py
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2015-02-16 10:46:28 +0100
committerGravatar Walter Purcaro <vuolter@gmail.com> 2015-02-16 10:46:28 +0100
commitce1c2b6b05c08b669357947e61ae40efce7fc50f (patch)
tree0b5f7996960cf35c4eface53a89eba18a37519b7 /module/plugins/addon/WindowsPhoneToastNotify.py
parentFix filename case (diff)
downloadpyload-ce1c2b6b05c08b669357947e61ae40efce7fc50f.tar.xz
module temp
Diffstat (limited to 'module/plugins/addon/WindowsPhoneToastNotify.py')
-rw-r--r--module/plugins/addon/WindowsPhoneToastNotify.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/module/plugins/addon/WindowsPhoneToastNotify.py b/module/plugins/addon/WindowsPhoneToastNotify.py
new file mode 100644
index 000000000..0ac6719e1
--- /dev/null
+++ b/module/plugins/addon/WindowsPhoneToastNotify.py
@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+
+import httplib
+import time
+
+from pyload.plugin.Addon import Addon
+
+
+class WindowsPhoneToastNotify(Addon):
+ __name__ = "WindowsPhoneToastNotify"
+ __type__ = "addon"
+ __version__ = "0.03"
+
+ __config__ = [("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"""
+ __license__ = "GPLv3"
+ __authors__ = [("Andy Voigt", "phone-support@hotmail.de")]
+
+
+ def getXmlData(self):
+ myxml = ("<?xml version='1.0' encoding='utf-8'?> <wp:Notification xmlns:wp='WPNotification'> "
+ "<wp:Toast> <wp:Text1>Pyload Mobile</wp:Text1> <wp:Text2>Captcha waiting!</wp:Text2> "
+ "</wp:Toast> </wp:Notification>")
+ 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 captchaTask(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()