Ejemplo n.º 1
0
class Pronto(Daemon):
    
    def setup(self):
                
        self.pyrowl = Pyrowl()
        
        __dir__ = os.path.dirname(os.path.abspath(__file__))
        filepath = os.path.join(__dir__, 'api.key')
        if os.path.isfile(filepath):
            keys = filter(None, open(filepath,'r').read().split("\n"))
            self.pyrowl.addkey(keys)   
        else:
            print "Pronto - Send notifications to your iDevice via Prowl"
            print "Copyright (c) 2011 Luqman Aden"
            print ""
            print "No API key found. Create file name 'api.key' with on API per line."
    
    def pusher(self, application, event, description, url = '', priority = 0, batch = False):
                
        self.pyrowl.push(application, event, description, url, priority, batch)
                
    def run(self):
        
        # Monitor DBUS    
        DBusGMainLoop(set_as_default=True)
        
        bus = dbus.SessionBus()
        
        # We only want notifications, filter the rest out
        bus.add_match_string_non_blocking('interface=org.freedesktop.Notifications,eavesdrop=true')
        
        # Send the notifications/events to our handler
        bus.add_message_filter(self.handler)
        
        loop = gobject.MainLoop()
        loop.run()
                
    def handler(self, *args):
                
        if args[1].get_interface() == "org.freedesktop.Notifications" and args[1].get_member() == "Notify":
    
            method_args = args[1].get_args_list()
            
            if len(method_args[3].strip()):
                
                application = method_args[0]
                event = "%s" % method_args[3]
                description = "%s" % strip_tags(method_args[4])
                priority = 0 # Set to normal by default
                
                if method_args[6].get('urgency', 1) == 0:  
                    priority = -1 # Low
                elif method_args[6].get('urgency', 1) == 1:
                    priority = 0 # normal
                elif method_args[6].get('urgency', 1) == 2:
                    priority = 2 # critical
                
                pusher_process = Process(target=self.pusher, args=(application, event, description, '', priority, False))
                pusher_process.start()
Ejemplo n.º 2
0
class Pronto(Daemon):
    
    def setup(self):
                
        self.pyrowl = Pyrowl()
        
        if os.path.isfile('api.key'):
            keys = filter(None, open("api.key",'r').read().split("\n"))
            self.pyrowl.addkey(keys)   
        else:
            print "Pronto - Send notifications to your iDevice via Prowl"
            print "Copyright (c) 2011 Luqman Aden"
            print ""
            print "No API key found. Create file name 'api.key' with on API per line."
    
    def pusher(self, application, event, description, url = '', priority = 0, batch = False):
                
        self.pyrowl.push(application, event, description, url, priority, batch)
                
    def run(self):
        
        # Monitor DBUS    
        DBusGMainLoop(set_as_default=True)
        
        bus = dbus.SessionBus()
        
        # We only want notifications, filter the rest out
        bus.add_match_string_non_blocking('interface=org.freedesktop.Notifications')
        
        # Send the notifications/events to our handler
        bus.add_message_filter(self.handler)
        
        loop = gobject.MainLoop()
        loop.run()
                
    def handler(self, *args):
                
        if args[1].get_interface() == "org.freedesktop.Notifications" and args[1].get_member() == "Notify":
    
            method_args = args[1].get_args_list()
            
            if len(method_args[3].strip()):
                
                application = method_args[0]
                event = "%s" % method_args[3]
                description = "%s" % strip_tags(method_args[4])
                priority = 0 # Set to normal by default
                
                if method_args[6].get('urgency', 1) == 0:  
                    priority = -1 # Low
                elif method_args[6].get('urgency', 1) == 1:
                    priority = 0 # normal
                elif method_args[6].get('urgency', 1) == 2:
                    priority = 2 # critical
                
                pusher_process = Process(target=self.pusher, args=(application, event, description, '', priority, False))
                pusher_process.start()
Ejemplo n.º 3
0
 def setup(self):
             
     self.pyrowl = Pyrowl()
     
     if os.path.isfile('api.key'):
         keys = filter(None, open("api.key",'r').read().split("\n"))
         self.pyrowl.addkey(keys)   
     else:
         print "Pronto - Send notifications to your iDevice via Prowl"
         print "Copyright (c) 2011 Luqman Aden"
         print ""
         print "No API key found. Create file name 'api.key' with on API per line."
Ejemplo n.º 4
0
 def setup(self):
             
     self.pyrowl = Pyrowl()
     
     __dir__ = os.path.dirname(os.path.abspath(__file__))
     filepath = os.path.join(__dir__, 'api.key')
     if os.path.isfile(filepath):
         keys = filter(None, open(filepath,'r').read().split("\n"))
         self.pyrowl.addkey(keys)   
     else:
         print "Pronto - Send notifications to your iDevice via Prowl"
         print "Copyright (c) 2011 Luqman Aden"
         print ""
         print "No API key found. Create file name 'api.key' with on API per line."
Ejemplo n.º 5
0
Archivo: test.py Proyecto: BoGu5/pyrowl
def main(keys):
    global p
    pkey = None
    
    p = Pyrowl()
    if os.path.isfile("myproviderkey"):
        pkey = open("myproviderkey",'r').readline().strip()
        p.providerkey(pkey)

    p.addkey(keys)
    res = p.push("test app", 'test event', 'test msg', 'http://example.com', batch_mode=False)
    pprint(res)
Ejemplo n.º 6
0
def main(keys):
    global p
    pkey = None

    p = Pyrowl()
    if os.path.isfile("myproviderkey"):
        pkey = open("myproviderkey", 'r').readline().strip()
        p.providerkey(pkey)

    p.addkey(keys)
    res = p.push("test app",
                 'test event',
                 'test msg',
                 'http://example.com',
                 batch_mode=False)
    pprint(res)
Ejemplo n.º 7
0
class Notify(eg.ActionBase):
    class text:
        errMess2 = 'NMA: There is no valid API key available.'
        errMess3 = 'NMA: Sending notification failed.'
        errMess4 = 'Cause: %s (error %s)'
        empty = '>>EMPTY<<'
        apiLabel = "Use these API keys:"
        appLabel = "Application:"
        eventLabel = "Event:"
        descrLabel = "Description (payload):"
        urlLabel = "Url:"
        priorityLabel = "Priority:"
        batch_mode = "Batch mode:"
        resType = 'EventGhost result:'
        resTypes = ('Full', 'Short')
        subst = 'Use a short description instead of the API key'
        prnt = 'The result to print to EventGhost log'
        rslt = "Result: %s"
        priorities = ("Very Low", "Moderate", "Normal", "High", "Emergency")
        batchTip = """Warning: using batch_mode will return error only if all
 the API keys are bad (and success if at least one API is OK)"""

    def GetLabel(self, apikeys, app, event, description, url, priority,
                 batch_mode, resType, subst, prnt):
        #WARNING:self.plugin.apikeys may be an empty list at the time of the first call
        # therefore, we use self.plugin.info.treeItem ... GetArguments()[0]
        trItem = self.plugin.info.treeItem
        apis = list(trItem.GetArguments())[0]
        event = event if event else self.text.empty
        nmaList, prowlList = self.plugin.GetApiKeyLsts(apikeys, apis)
        ix = -1 + int(nmaList > []) + 2 * int(prowlList > [])
        wx.CallAfter(self.plugin.changeIcon, self, ix)
        return "%s: %s" % (self.name, event)

    def __call__(self,
                 apikeys=[],
                 app=u"EventGhost",
                 event=u"{eg.event.string}",
                 description=u"{eg.event.payload}",
                 url="",
                 priority=0,
                 batch_mode=False,
                 resType=1,
                 subst=True,
                 prnt=False):
        text = self.text
        app = eg.ParseString(app) if app else "EventGhost"
        event = eg.ParseString(event) if event else text.empty
        description = eg.ParseString(
            description) if description else text.empty
        url = eg.ParseString(url)
        if url:
            if url.lower()[:7] != r"http://" and url.lower(
            )[:8] != r"https://":
                url = r"http://" + url
        nmaResult = {}
        prowlResult = {}
        nmaRes = {}
        prowlRes = {}
        apis = self.plugin.apikeys
        nmaList, prowlList = self.plugin.GetApiKeyLsts(apikeys, apis)
        if nmaList:
            try:
                devel = self.plugin.devel if self.plugin.devel else None
                mess = PyNMA(nmaList, devel)
                nmaRes = mess.push(app, event, description, url, None,
                                   priority, batch_mode)
            except Exception, e:
                i = e.args[0]
                s = e.args[1].decode(eg.systemEncoding)
                eg.PrintError(text.errMess3 + "\n" + text.errMess4 %
                              (s, str(i)))
        if prowlList:
            try:
                provid = self.plugin.provid if self.plugin.provid else None
                mess = Pyrowl(prowlList, provid)
                prowlRes = mess.push(app, event, description, url, priority,
                                     batch_mode)
            except Exception, e:
                i = e.args[0]
                s = e.args[1].decode(eg.systemEncoding)
                eg.PrintError(text.errMess3 + "\n" + text.errMess4 %
                              (s, str(i)))