Beispiel #1
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."
Beispiel #2
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)
Beispiel #3
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)))