Beispiel #1
0
def entry_face():
    mysql = SQLUtil()
    if request.method == 'POST':
        data = request.form.get('face-info')
        face_info = data.split('base64,')[1]
        aip = tylt_AipFace()
        face_detect_result = aip.face_detect(face_info)
        if face_detect_result['error_code'] != 0:
            return 'failed'
        face_num = face_detect_result['result']['face_num']
        if face_num == 0:
            return 'no_face'
        elif face_num != 1:
            return 'not_only_one_face'
        elif face_detect_result['result']['face_list'][0]['face_type'][
                'probability'] < 0.9:
            return 'not_clear'
        else:
            try:
                sql = "UPDATE user SET face_info = '%s' where name= '%s' " % (
                    face_info, 'tylt')
                mysql.update(sql)
                mysql.dispose()
                return 'success'
            except Exception as e:
                print(e)
                return '<h1>录入人脸时发生未知错误,请返回重试</h1>'
    return render_template('register_by_face.html')
Beispiel #2
0
def sign_by_face():
    mysql = SQLUtil()
    if request.method == 'POST':
        data = request.form.get('face-info')
        username = request.form.get('username')
        face_info = data.split('base64,')[1]
        aip = tylt_AipFace()
        try:
            sql = "SELECT face_info FROM user WHERE name='%s'" % username
            face_info_from_db = mysql.getOne(sql)  # 获取数据库中的人脸信息
            mysql.dispose()
            if not face_info_from_db['face_info']:
                return 'no_face_info'  # 数据库中没有人脸信息
            else:
                aip.face_constrast_img1 = face_info_from_db['face_info']
                aip.face_constrast_img2 = face_info
                contrast_result = aip.face_contrast()
                if contrast_result['error_code'] == 0 and contrast_result[
                        'result']['score'] >= 80:
                    session['un'] = username
                    return 'success'

        except Exception as e:
            print(e)
            return '<h1>服务器发生未知错误,请稍后重试</h1>'
    return render_template('sign_in_by_face.html')
Beispiel #3
0
def login():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        mysql = SQLUtil()

        sql = "SELECT * FROM user WHERE name='%s'" % username
        res = mysql.getAll(sql)
        mysql.dispose()
        if res == False:
            message = "您还没在本站进行注册!"
            return render_template('login.html', message=message)
        else:
            from werkzeug.security import generate_password_hash, check_password_hash
            if res[0]['name'] == username and check_password_hash(
                    res[0]['password'], password):
                user = res[0]['name']
                while user is not None:
                    resp = make_response(redirect(url_for('home')))
                    resp.set_cookie('userID', user)
                    return resp

            else:
                message = "您输入的密码错误!"
                return render_template('login.html', message=message)
    else:
        return render_template('login.html')
Beispiel #4
0
def register():
    if request.method == 'GET':
        return render_template('register.html')
    else:
        mysql = SQLUtil()
        username = request.form['username']

        from werkzeug.security import generate_password_hash
        password = generate_password_hash(request.form['password'])
        sql = "INSERT INTO user(name, password) VALUE ('%s','%s')" % (username,
                                                                      password)
        mysql.insertOne(sql)
        mysql.dispose()
        return render_template('login.html')
Beispiel #5
0
def parseOnePage(url):
    """

    :param url:
    :return:
    """
    header = {
        "User-Agent":
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
    }
    ret = requests.get(url, headers=header)
    html = etree.HTML(ret.text)
    title = html.xpath('//div[*]/div[*]/div[*]/div[/*]/p[*]//text()')

    for i in range(len(title)):
        mysql = SQLUtil()
        sql = "INSERT INTO birthdayarticle(content) VALUES ('%s')" % (title[i])
        mysql.insertOne(sql)
        mysql.dispose()