예제 #1
0
def newMemberApi():
    filter_list = []
    adminPhone = app.config.get('SMS_ADMIN_PHONE')
    # print request.form
    for i in request.form:
        if request.form[i] == '' or request.form[i] == 'null':
            filter_list.append(i)
    if filter_list:
        return jsonify({'status': 'lacked', 'msg': filter_list})
    name = request.form['join_name']
    description = request.form['join_description']
    num = str(request.form['join_phone'])
    idCode = str(request.form['idCode'])
    if idCode != cache.get(num):
        return jsonify({'status': 'wrongcode', 'msg': ''})

    status = 'pending'

    newMsg = Message(name=name,
                     description=description,
                     mobile=num,
                     status=status)
    db.session.add(newMsg)
    db.session.commit()
    cache.delete(num)
    notiMsg = '{"name": "%s","number":"%s"}' % (name, num)
    # sendNotiResult = sendSMS('noti_v', adminPhone, notiMsg).send()

    return jsonify(status='ok', error=u'')
예제 #2
0
def loginApi():
    mobile = str(request.form['phone'])
    idCode = str(request.form['idCode'])
    if idCode == cache.get(mobile):
        return jsonify({'status': 'bad idCode'})
    if request.form['password'] == users[mobile]['password']:
        user = User()
        user.id = mobile
        flask_login.login_user(user)
        cache.delete(mobile)
        return jsonify({'status': 'OK'})

    return jsonify({'status': 'bad login'})
예제 #3
0
def newCluApi():
    adminPhone = app.config.get('SMS_ADMIN_PHONE')
    filter_list = []
    for i in request.form:
        if request.form[i] == '' or request.form[i] == 'null':
            filter_list.append(i)
    if filter_list:
        return jsonify({'status': 'lacked', 'msg': filter_list})
    find_date = dateConvert(request.form['find_date'])
    find_loc_province = request.form['find_loc_province']
    find_loc_city = request.form['find_loc_city']
    find_loc_town = request.form['find_loc_town']
    description = request.form['description']
    c_name = request.form['contact_name']
    c_tel = str(request.form['contact_phone'])
    idCode = request.form['idCode']
    img = request.files['img']
    if not img:
        return jsonify({'status': 'nopic', 'msg': ''})
    if idCode != cache.get(c_tel):
        return jsonify({'status': 'wrongcode', 'msg': ''})
    sourceResult = thumb.upload_file(img, UPLOAD_URL, QINIU_DOMAIN,
                                     qiniu_store)
    if sourceResult['result'] == 1:
        sourceImg = sourceResult['localUrl']
        clu = Findingchildren(img=sourceImg,
                              finding_time=find_date,
                              source='guijia',
                              c_name=c_name,
                              c_tel=c_tel,
                              loc_province=find_loc_province,
                              loc_city=find_loc_city,
                              loc_town=find_loc_town,
                              description=description,
                              status='pending')

        db.session.add(clu)
        db.session.commit()
        cache.delete(c_tel)
        tag = 'missingchildren'
        rawSearchResult = Face.search(sourceImg, tag)
        searchResult = searchResultHandleForWeb(rawSearchResult)
        if searchResult['status'] != 'ok':
            # searchrecord = Searchrecord(tag=tag, source='findingchildren', source_id=clu.id,
            #                             confidence=0,
            #                             detail=json.dumps(rawSearchResult['detail']),
            #                             theshold=json.dumps(rawSearchResult['thresholds']),target=rawSearchResult['token'],status='error')
            # db.session.add(searchrecord)
            # db.session.commit()
            return jsonify(status='failed', error=u'服务器出错,请稍后再试')
        else:
            searchrecord = Searchrecord(
                tag=tag,
                source='findingchildren',
                source_id=clu.id,
                confidence=rawSearchResult['confidence'],
                detail=json.dumps(rawSearchResult['detail']),
                theshold=json.dumps(rawSearchResult['thresholds']),
                target=rawSearchResult['token'],
                status=rawSearchResult['status'])
            db.session.add(searchrecord)
            db.session.commit()
            notiMsg = u'{"name": "%s","number":"%s"}' % (
                u'新线索' + str(rawSearchResult['confidence']), c_tel)

        uploadFaceSetResult = Face.uploadFaces([sourceImg], 'findingchildren')
        if uploadFaceSetResult[0][0] == "":
            return jsonify(status='failed',
                           error=u'服务器出错,请稍后再试',
                           description=u"",
                           title="")

        fChildrenFace = Fchildrenface(clu.id, uploadFaceSetResult[0][0])
        db.session.add(fChildrenFace)
        db.session.commit()
        sendNotiResult = sendSMS(u'noti_a', adminPhone, notiMsg).send()
        return jsonify(status='ok', error=u'', msg=searchResult)
    else:
        return jsonify(status='failed', error=u'服务器出错,请稍后再试')
예제 #4
0
def profileApi():
    adminPhone = app.config.get('SMS_ADMIN_PHONE')
    filter_list = []
    for i in request.form:
        if request.form[i] == '' or request.form[i] == 'null':
            filter_list.append(i)
    if filter_list:
        return jsonify({'status': 'lacked', 'msg': filter_list})

    name = request.form['lost_name']
    gender = request.form['gender']
    birthday = dateConvert(request.form['birthday'])
    missing_time = dateConvert(request.form['lost_date'])
    missing_location_province = request.form['lost_loc_province']
    missing_location_city = request.form['lost_loc_city']
    missing_location_town = request.form['lost_loc_town']
    height = request.form['height']
    description = request.form['description']
    c_name = request.form['contact_name']
    c_tel = str(request.form['contact_phone'])
    idCode = str(request.form['idCode'])
    img = request.files['img']
    if not img:
        return jsonify({'status': 'nopic', 'msg': ''})
    if idCode != cache.get(c_tel):
        return jsonify({'status': 'wrongcode', 'msg': ''})
    sourceResult = thumb.upload_file(img, UPLOAD_URL, QINIU_DOMAIN,
                                     qiniu_store)
    if sourceResult['result'] == 1:
        sourceImg = sourceResult['localUrl']
        profile = Missingchildren(
            bid=None,
            image=sourceImg,
            name=name,
            gender=gender,
            birthday=birthday,
            height=str(height) + u'厘米',
            missing_time=missing_time,
            source='guijia',
            c_name=c_name,
            c_tel=c_tel,
            confirm_location='',
            missing_location_province=missing_location_province,
            missing_location_city=missing_location_city,
            missing_location_town=missing_location_town,
            description=description,
            comment='',
            login_time=time.time(),
            volunteer='',
            status='pending',
            short_name=name.split('(')[0].split(u'(')[0].split(' ')[0])

        db.session.add(profile)
        db.session.commit()
        cache.delete(c_tel)
        tag = 'findingchildren'
        rawSearchResult = Face.search(sourceImg, tag)
        searchResult = searchResultHandleForWeb(rawSearchResult)
        uploadFaceSetResult = Face.uploadFaces([sourceImg], 'missingchildren')

        if uploadFaceSetResult[0][0] == "":
            return jsonify(status='failed',
                           error=u'服务器出错,请稍后再试',
                           description=u"",
                           title="")
        # print uploadFaceSetResult
        CF = Childrenface(childrenId=profile.id,
                          token=uploadFaceSetResult[0][0])
        db.session.add(CF)
        db.session.commit()
        description = ""
        title = ""
        if searchResult['stage'] > 0:
            description = searchResult['description']
            title = searchResult['title']
        # print searchResult['description']
        notiMsg = '{"name": "%s","number":"%s"}' % (name, c_tel)
        sendNotiResult = sendSMS('noti_a', adminPhone, notiMsg).send()

        return jsonify(status='ok',
                       error=u'',
                       title=title,
                       description=description)
    else:
        return jsonify(status='failed',
                       error=u'服务器出错,请稍后再试',
                       description=u"",
                       title="")
예제 #5
0
    def getResponse(self, body_text):
        face = Face
        wechat = self.wechat
        if wechat.check_signature(self.signature, self.timestamp, self.nonce):
            try:
                self.wechat.parse_data(body_text)

            except ParseError:
                return 0
            id = wechat.message.id
            target = wechat.message.target
            source = wechat.message.source
            time = wechat.message.time
            type = wechat.message.type
            raw = wechat.message.raw
            if isinstance(wechat.message, TextMessage):
                content = wechat.message.content
                return wechat.response_text(content)
            elif isinstance(wechat.message, ImageMessage):
                if cache.get('wechat_' + source):
                    #too fast
                    title = u'对不起'
                    description = u'请不要过于频繁发送图片'
                    url = app.config.get('HOST')
                    return wechat.response_news([{
                        "title": title,
                        "description": description,
                        "url": url
                    }])
                else:
                    picurl = wechat.message.picurl
                    uploadFaceSetResult = Face.uploadFaces([picurl],
                                                           'findingchildren')
                    media_id = wechat.message.media_id
                    searchResult = face.search(picurl, 'missingchildren')
                    rawResult = searchResultHandleForWeb(searchResult)
                    if 'token' not in searchResult:
                        return wechat.response_text(u"服务器正忙")
                    title = rawResult['title']
                    sameChildRecord = Childrenface.query.filter_by(
                        token=searchResult['token']).first()
                    description = rawResult['description']
                    url = app.config.get('HOST')
                    if sameChildRecord:
                        sameChild = Missingchildren.query.filter_by(
                            id=sameChildRecord.childrenId).first()
                        return wechat.response_news([{
                            "title": title,
                            "description": description,
                            "picurl": sameChild.image
                        }])
                    else:
                        return wechat.response_news([{
                            "title": title,
                            "description": description,
                            "url": url
                        }])

            else:
                return wechat.response_text(u"请上传疑似走失者的图片")

        else:
            return wechat.response_text(u"服务器正在修复")