Exemplo n.º 1
0
def PictureReplyClassification(message):
    #a=ImageReco()
    begin = time.time()
    url_img = message.img
    #print('url:')
    #print(url_img)

    begin_time = time.time()
    image = aImg.getImage(url_img)
    end_time = time.time()
    print("get image" + str(end_time - begin_time))

    print("compressed length:" + str(len(image)))

    begin_time = time.time()
    problem_list = aImg.recognize(image)
    end_time = time.time()
    print("rec image" + str(end_time - begin_time))
    problem_count = len(problem_list)

    print(problem_list)
    end = time.time()
    time1 = ""
    time1 = str(end - begin)
    print("the program has run " + time1 + 's')
    if ((end - begin) > 3.5):
        return SuccessReply(message=message)
    else:
        return GetAnswerImg(problem_list, message)
Exemplo n.º 2
0
def unsubscribe(message):
    session = DBSession()
    wechat = session.query(Wechat).filter(
        Wechat.openid == message.source).one_or_none()
    if wechat:
        wechat.subscribe = False
        wechat.unsubscribe_time = datetime.datetime.now()
    else:
        wechat = Wechat(openid=message.source, subscribe=False,
                        unsubscribe_time=datetime.datetime.now(), create_time=datetime.datetime.now())
        session.add(wechat)
    session.commit()
    session.close()

    return SuccessReply()
Exemplo n.º 3
0
def response(message):
    reply = SuccessReply(message=message)
    #reply = 'success'
    return reply
Exemplo n.º 4
0
def test_success_reply():
    assert SuccessReply().render() == "success"
Exemplo n.º 5
0
def common_replay(message):
    return SuccessReply(message)
Exemplo n.º 6
0
def unsubscribe_message(message):
    return SuccessReply(message)
Exemplo n.º 7
0
def image_message(message):
    handle_image_message(message)
    return SuccessReply(message)
Exemplo n.º 8
0
def unsubscribe_message(message):
    un_subscribe_message_func(message)
    return SuccessReply(message)
Exemplo n.º 9
0
def respond_others(message):
    return SuccessReply()
Exemplo n.º 10
0
def test_process_unknown_function_reply():
    reply = SuccessReply()
    assert process_function_reply(reply) == reply
Exemplo n.º 11
0
def subscribe(message):
    template_id = 'SO8Yjl0gcmNI0HW-pzgkpJqlPz0GV28llZNVoBjsspA'
    user = myrobot.client.get_user_info(message.source)
    if user:
        session = DBSession()
        wechat = session.query(Wechat).filter(
            Wechat.openid == user['openid']).one_or_none()
        if wechat:
            wechat.subscribe = True
            wechat.nickname = user['nickname']
            wechat.sex = user.get('sex', 0)
            wechat.city = user.get('city')
            wechat.country = user.get('country')
            wechat.province = user.get('province')
            wechat.language = user.get('language')
            wechat.headimgurl = user.get('headimgurl')
            wechat.subscribe_time = datetime.datetime.fromtimestamp(
                int(user['subscribe_time']))
            wechat.unionid = user.get('unionid')
            wechat.remark = user.get('remark')
            wechat.groupid = user.get('groupid')
            wechat.tagid_list = ','.join(
                [str(x) for x in user.get('tagid_list', [])])
            wechat.subscribe_scene = user.get('subscribe_scene')
            wechat.qr_scene_str = user.get('qr_scene_str')
        else:
            wechat = Wechat(
                openid=user['openid'],
                nickname=user['nickname'],
                subscribe=user['subscribe'],
                sex=user.get('sex', 0),
                city=user.get('city'),
                country=user.get('country'),
                province=user.get('province'),
                language=user.get('language'),
                headimgurl=user.get('headimgurl'),
                subscribe_time=datetime.datetime.fromtimestamp(
                    int(user['subscribe_time'])),
                unionid=user.get('unionid'),
                remark=user.get('remark'),
                groupid=user.get('groupid'),
                tagid_list=','.join([str(x)
                                     for x in user.get('tagid_list', [])]),
                subscribe_scene=user.get('subscribe_scene'),
                qr_scene_str=user.get('qr_scene_str'),
                create_time=datetime.datetime.now()
            )
            session.add(wechat)
        session.commit()
        session.close()
        r = myrobot.client.post(
            url="https://api.weixin.qq.com/cgi-bin/message/template/send",
            data={
                "touser": message.source,
                "template_id": template_id,
                "data": {
                    "first": {
                        "value": "欢迎关注'千济方开发者开台'公众号",
                        "color": "#173177"
                    },
                    "keyword1": {
                        "value": "你可点击进入,进行账号绑定.",
                        "color": "#173177"
                    },
                    "keyword2": {
                        "value": "13888888888",
                        "color": "#173177"
                    },
                    "remark": {
                        "value": "如有疑问,请联系小孟",
                        "color": "#173177"
                    }
                },
                "miniprogram": {
                    "appid": "wx79edc80703771261",
                    #"pagepath": "pages/monitor/monitor"
                }
            }
        )
        return SuccessReply()
        # return 'Hello %s!' % user['nickname']
    else:
        return 'Hello My Friend!'