client.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:pybot 作者: aster1sk 项目源码 文件源码
def mq_callback(ch, method, properties, body) :

    body = loads(body)
    args = body.get("args")
    host = body.get("host")
    port = body.get("host")
    time = body.get("time")
    uuid = body.get("uuid")
    raw = body.get("raw")
    event = body.get("event")
    col.log.insert(body)
        result = None
        pprint(body)

        for rule in col.rules.find() :
            title = rule.get("title")
            condition = rule.get("condition")
            actions = rule.get("actions")
            execute = rule.get('exec')

            for k,v in condition.iteritems() :

                try :
                    test = args[int(k)] == v
                except :
                    pass

                if test :

                    print "Executing %s" % title
                    # See if there's an exec block
                    if execute :
                        typeof = execute.get('type')
                        valof = execute.get('value')
                        print "%s:%s" % (typeof, valof)

                        if typeof == 'JSON' :
                            try :
                                result = requests.post(valof, json=dumps(body)).json().get('result')
                                args.append(result)
                            except :
                                pass

                    for action in actions :
                        # this stupid thing just replaces vars in the string
                        argdict = dict(k for k in enumerate(args))
                        argdict.update({'result': result})
                        final = dict([(str(k), v) for k, v in argdict.items()])
                        try :
                            msg = action % final # {str(k) : v for k, v in enumerate(args)}
                        except :
                            return
                        print "MESSAGE : %s" % msg
                        for ms in msg.split("\n") :
                            sock.send(ms+"\r\n")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号