diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-10-20 20:11:02 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-10-20 20:11:02 +0200 |
commit | 22cc829d68fa129f0d2bd33da2ea479c51563e7e (patch) | |
tree | fe71b3a8e039e379782d4fb5305a645be5c6285e /module/plugins/hooks/WindowsPhoneNotify.py | |
parent | Code cosmetics (diff) | |
download | pyload-22cc829d68fa129f0d2bd33da2ea479c51563e7e.tar.xz |
Notifier framework
Diffstat (limited to 'module/plugins/hooks/WindowsPhoneNotify.py')
-rw-r--r-- | module/plugins/hooks/WindowsPhoneNotify.py | 88 |
1 files changed, 7 insertions, 81 deletions
diff --git a/module/plugins/hooks/WindowsPhoneNotify.py b/module/plugins/hooks/WindowsPhoneNotify.py index e032508c0..3a72e0b39 100644 --- a/module/plugins/hooks/WindowsPhoneNotify.py +++ b/module/plugins/hooks/WindowsPhoneNotify.py @@ -3,13 +3,13 @@ import httplib import time -from module.plugins.internal.Addon import Addon, Expose +from module.plugins.internal.Notifier import Notifier -class WindowsPhoneNotify(Addon): +class WindowsPhoneNotify(Notifier): __name__ = "WindowsPhoneNotify" __type__ = "hook" - __version__ = "0.14" + __version__ = "0.15" __status__ = "testing" __config__ = [("activated" , "bool", "Activated" , False), @@ -30,55 +30,8 @@ class WindowsPhoneNotify(Addon): ("Walter Purcaro", "vuolter@gmail.com" )] - def init(self): - self.event_map = {'allDownloadsProcessed': "all_downloads_processed", - 'plugin_updated' : "plugin_updated" } - - self.last_notify = 0 - self.notifications = 0 - - - def plugin_updated(self, type_plugins): - if not self.get_config('notifyupdate'): - return - - self.notify(_("Plugins updated"), str(type_plugins)) - - - def activate(self): - self.key = (self.get_config('push-id'), self.get_config('push-url')) - - - def exit(self): - if not self.get_config('notifyexit'): - return - - if self.pyload.do_restart: - self.notify(_("Restarting pyLoad")) - else: - self.notify(_("Exiting pyLoad")) - - - def captcha_task(self, task): - if not self.get_config('notifycaptcha'): - return - - self.notify(_("Captcha"), _("New request waiting user input")) - - - def package_finished(self, pypack): - if self.get_config('notifypackage'): - self.notify(_("Package finished"), pypack.name) - - - def all_downloads_processed(self): - if not self.get_config('notifyprocessed'): - return - - if any(True for pdata in self.pyload.api.getQueue() if pdata.linksdone < pdata.linkstotal): - self.notify(_("Package failed"), _("One or more packages was not completed successfully")) - else: - self.notify(_("All packages finished")) + def get_key(self): + return self.get_config('push-id'), self.get_config('push-url') def get_xml_data(self, msg): @@ -87,30 +40,8 @@ class WindowsPhoneNotify(Addon): "</wp:Toast> </wp:Notification>" % msg) - @Expose - def notify(self, - event, - msg="", - key=(None, None)): - - id, url = key or self.key - if not id or not url: - return - - if self.pyload.isClientConnected() and not self.get_config('ignoreclient'): - return - - elapsed_time = time.time() - self.last_notify - - if elapsed_time < self.get_config("sendtimewait"): - return - - if elapsed_time > 60: - self.notifications = 0 - - elif self.notifications >= self.get_config("sendpermin"): - return - + def send(self, event, msg, key): + id, url = key request = self.get_xml_data("%s: %s" % (event, msg) if msg else event) webservice = httplib.HTTP(url) @@ -123,8 +54,3 @@ class WindowsPhoneNotify(Addon): webservice.endheaders() webservice.send(request) webservice.close() - - self.last_notify = time.time() - self.notifications += 1 - - return True |