コード例 #1
0
ファイル: loglet.py プロジェクト: dahlia/loglet
def logmeta(longid):
    """Change metadata for a log."""

    if 'title' in request.form:
        title = request.form['title'][:app.config['MAX_TITLE_LENGTH']].strip()
        logid, _ = _get_log(longid)
        app.logger.debug("log %s title changed to %s" % (longid, repr(title)))
        with g.db:
            g.db.execute("UPDATE logs SET name=? WHERE id=?", (title, logid))

    if 'notifoname' in request.form:
        username = request.form['notifoname'][:app.config['MAX_NOTIFO_LENGTH']]
        username = username.strip()

        # Try confirming with Notifo.
        if username:
            resp = notifo.subscribe_user(app.config['NOTIFO_USER'],
                                         app.config['NOTIFO_SECRET'],
                                         username)
            app.logger.debug('log %s notifo user changed; response: %s' %
                             (longid, repr(resp)))
            if resp['status'] != 'success':
                # Successful subscribe. Change user.
                app.logger.warn('notifo subscribe failed; disabling')
                username = ''

        # Store either the successful username or a blank.
        logid, _ = _get_log(longid)
        with g.db:
            g.db.execute("UPDATE logs SET notifoname=? "
                         "WHERE id=?", (username, logid))

    return flask.redirect('/' + longid)
コード例 #2
0
ファイル: notifo_cli.py プロジェクト: wozz/notifo.py
def main():
    """ main function """
    # get options and arguments
    (parser, options, args) = init_parser()

    # initialize result variable
    result = None

    # check for values which are always needed
    if not options.user:
        parser.error("No user given.")
    if not options.secret:
        parser.error("No API secret given.")
    if not options.name:
        parser.error("No recipient given.")

    if not options.message_type:
        options.message_type = "notification"

    if len(args) < 1:
        result = notifo.subscribe_user(options.user, options.secret, options.name)
    else:
        params = {}
        params["to"] = options.name
        m = ''
        for a in args:
            m = "%s %s" %(m, a)
        params["msg"] = m
        
        if options.message_type == "message":
            result = notifo.send_message(options.user, options.secret, **params)
        elif options.message_type == "notification":
            if options.label:
                params["label"] = options.label
            if options.title:
                params["title"] = options.title
            if options.callback:
                params["uri"] = options.callback
            result = notifo.send_notification(options.user,options.secret, **params)


    if result is None:
        print "Something went wrong. Check parameters and try again."
コード例 #3
0
ファイル: notifo_cli.py プロジェクト: haqthat/notifo.py
def main():
    """ main function """
    # get options and arguments
    (parser, options, args) = init_parser()

    # initialize result variable
    result = None

    # check for values which are always needed
    if not options.user:
        parser.error("No user given.")
    if not options.secret:
        parser.error("No API secret given.")
    if not options.name:
        parser.error("No recipient given.")

    # If there is no message, we probably want to subscribe a user
    if len(args) < 1:
        result = notifo.subscribe_user(options.user, options.secret,
                                       options.name)
    else:
        params = {}
        params["to"] = options.name
        m = ''
        for a in args:
            m = "%s %s" % (m, a)
        params["msg"] = m

        if options.message == True:
            result = notifo.send_message(options.user, options.secret,
                                         **params)
        else:
            if options.label:
                params["label"] = options.label
            if options.title:
                params["title"] = options.title
            if options.callback:
                params["uri"] = options.callback
            result = notifo.send_notification(options.user, options.secret,
                                              **params)

    if result is None:
        print "Something went wrong. Check parameters and try again."
コード例 #4
0
 def test_subscribe_failed(self):
     res = subscribe_user(self.provider, "token", "test_user")
     self.assertEqual(res["response_code"], 401)
コード例 #5
0
 def test_subscribe(self):
     res = subscribe_user(self.provider, self.token, "test_user")
     self.assertEqual(res["response_code"], 2202)
コード例 #6
0
 def test_subscribe_failed(self):
     res = subscribe_user(self.provider, "token", "test_user")
     self.assertEqual(res["response_code"], 401)
コード例 #7
0
 def test_subscribe(self):
     res = subscribe_user(self.provider, self.token, "test_user")
     self.assertEqual(res["response_code"], 2202)