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')
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')
def username_check(): if request.method == "GET": username = request.args["username"] mysql = SQLUtil() sql_user = "******" % username user_result = mysql.getOne(sql_user) if user_result['COUNT(name)'] == 0: print(jsonify({"user_exits": False})) return jsonify({"user_exits": False}) else: print(jsonify({"user_exits": True})) return jsonify({"user_exits": True}) else: return render_template("register_by_face.html")
def save_image(item, count): try: response = requests.get(item.get('image')) if response.status_code == 200: file_path = save_dir + '{0}.{1}'.format(str(count), 'jpg') if not os.path.exists(file_path): with open(file_path, 'wb') as f: f.write(response.content) else: mysql = SQLUtil() sql = "INSERT INTO img (imgurl) VALUES ('%s')" % file_path mysql.insertOne(sql) print('下载到的目录', file_path) except requests.ConnectionError: print('下载图片失败')
def username_check(): if request.method == "GET": username = request.args["username"] mysql = SQLUtil() sql_user = "******" % username user_result = mysql.getOne(sql_user) if user_result['COUNT(name)'] == 0: print(jsonify({"user_exits": False})) return jsonify({"user_exits": False}) else: resp = make_response(redirect(url_for('home'))) resp.set_cookie('userID', username) print(jsonify({"user_exits": True})) return jsonify({"user_exits": True}) else: return render_template("register_by_face.html")
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')
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')
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()
def result(): mysql = SQLUtil() sql = "SELECT title,content FROM article" result = mysql.getMany(sql, 15) data = dict(result=result, ) return data
from Utils.SQLtool import SQLUtil list = 'hahahhjjjjjj' mysql = SQLUtil() sql = "INSERT INTO img (imgurl) VALUE ('%s')" % list print(sql, mysql.insertOne(sql)) mysql.insertOne(sql)