import pymysql from flask import Flask,request,jsonify
app = Flask(__name__)
conn = pymysql.connect(host='127.0.0.1',port=3306,user='root',password='Yyzx150315_',charset='utf8',db='db2') cursor=conn.cursor()
@app.route('/register',methods=['POST']) def register(): id = request.form.get('id') id_num = request.form.get('id_num') name = request.form.get('name') height = request.form.get('height') weight = request.form.get('weight') body_fat = request.form.get('body_fat') bmi = request.form.get('bmi') fitness_station = request.form.get('fitness_station') age = request.form.get('age') gender = request.form.get('gender') phone_number = request.form.get('phone_number') image = request.form.get('image') create_time = request.form.get('create_time') update_time = request.form.get('update_time')
cursor.execute("insert into ms_information(id,id_num,name,height,weight,body_fat,bmi,fitness_station,age,gender,phone_number,image,create_time,update_time) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",(id,id_num,name,height,weight,body_fat,bmi,fitness_station,age,gender,phone_number,image,create_time,update_time)) conn.commit()
return jsonify({"code":200,"msg":'success'})
@app.route('/delete',methods=['POST']) def delete(): id_num = request.form.get('id_num')
cursor.execute("delete * from ms_information where id_num = %s",(id_num,)) return jsonify({"code": 200, "msg": 'success'})
@app.route('/update',methods=['POST']) def update(): id = request.form.get('id') id_num = request.form.get('id_num') name = request.form.get('name') height = request.form.get('height') weight = request.form.get('weight') body_fat = request.form.get('body_fat') bmi = request.form.get('bmi') fitness_station = request.form.get('fitness_station') age = request.form.get('age') gender = request.form.get('gender') phone_number = request.form.get('phone_number') image = request.form.get('image') create_time = request.form.get('create_time') update_time = request.form.get('update_time')
cursor.execute( "update ms_information set id =%s,id_num =%s,name =%s,height =%s,weight =%s,body_fat =%s,bmi =%s,fitness_station =%s,age =%s,gender =%s,phone_number =%s,image =%s,create_time =%s,update_time =%s", ( id, id_num, name, height, weight, body_fat, bmi, fitness_station, age, gender, phone_number, image, create_time, update_time)) conn.commit()
return jsonify({"code": 200, "msg": 'success'})
@app.route('/find_user', methods=['GET']) def find_user(): id_num =request.form.get('id_num') cursor.execute("select * from ms_information where id_num = %s",(id_num)) user = cursor.fetchone() if user: return jsonify({"code":200,"msg":'success'}) else: return jsonify({"code":400,"msg":'success'})
@app.route('/allfind_user', methods=['GET']) def allfind_user(): cursor.execute("select * from ms_information") user = cursor.fetchone() if user: return jsonify({"code":200,"msg":'success'}) else: return jsonify({"code":400,"msg":'success'})
@app.route('/find_id_num', methods=['GET']) def find_id_num(): id_num =request.form.get('id_num') cursor.execute("select * from ms_information where id_num = %s",(id_num)) user = cursor.fetchone() if user: return jsonify({"code":200,"msg":'success'}) else: return jsonify({"code":400,"msg":'success'})
@app.route('/find_id', methods=['GET']) def find_id(): id = request.form.get('id') cursor.execute("select * from ms_information where id = %s",(id)) user = cursor.fetchone() if user: return jsonify({"code":200,"msg":'success'}) else: return jsonify({"code":400,"msg":'success'})
@app.route('/find_name', methods=['GET']) def find_name(): name = request.form.get('name') cursor.execute("select * from ms_information where name = %s",(name)) user = cursor.fetchone() if user: return jsonify({"code":200,"msg":'success'}) else: return jsonify({"code":400,"msg":'success'})
@app.route('/find_height', methods=['GET']) def find_height(): height = request.form.get('height') cursor.execute("select * from ms_information where height = %s",(height)) user = cursor.fetchone() if user: return jsonify({"code":200,"msg":'success'}) else: return jsonify({"code":400,"msg":'success'})
@app.route('/find_weight', methods=['GET']) def find_weight(): weight = request.form.get('weight') cursor.execute("select * from ms_information where weight = %s",(weight)) user = cursor.fetchone() if user: return jsonify({"code":200,"msg":'success'}) else: return jsonify({"code":400,"msg":'success'})
@app.route('/find_body_fat', methods=['GET']) def find_body_fat(): body_fat = request.form.get('body_fat') cursor.execute("select * from ms_information where body_fat = %s",(body_fat)) user = cursor.fetchone() if user: return jsonify({"code":200,"msg":'success'}) else: return jsonify({"code":400,"msg":'success'})
@app.route('/find_bmi', methods=['GET']) def singlefind_user(): bmi = request.form.get('bmi') cursor.execute("select * from ms_information where bmi = %s",(bmi)) user = cursor.fetchone() if user: return jsonify({"code":200,"msg":'success'}) else: return jsonify({"code":400,"msg":'success'})
@app.route('/find_fitness_station', methods=['GET']) def find_fitness_station(): fitness_station = request.form.get('fitness_station') cursor.execute("select * from ms_information where fitness_station = %s",(fitness_station)) user = cursor.fetchone() if user: return jsonify({"code":200,"msg":'success'}) else: return jsonify({"code":400,"msg":'success'})
@app.route('/find_age', methods=['GET']) def find_age(): age = request.form.get('age') cursor.execute("select * from ms_information where age = %s",(age)) user = cursor.fetchone() if user: return jsonify({"code":200,"msg":'success'}) else: return jsonify({"code":400,"msg":'success'})
@app.route('/find_gender', methods=['GET']) def find_gender(): gender = request.form.get('gender') cursor.execute("select * from ms_information where gender = %s",(gender)) user = cursor.fetchone() if user: return jsonify({"code":200,"msg":'success'}) else: return jsonify({"code":400,"msg":'success'})
@app.route('/find_phone_number', methods=['GET']) def find_phone_number(): phone_number = request.form.get('phone_number') cursor.execute("select * from ms_information where phone_number = %s",(phone_number)) user = cursor.fetchone() if user: return jsonify({"code":200,"msg":'success'}) else: return jsonify({"code":400,"msg":'success'})
@app.route('/find_image', methods=['GET']) def find_image(): image = request.form.get('image') cursor.execute("select * from ms_information where image = %s",(image)) user = cursor.fetchone() if user: return jsonify({"code":200,"msg":'success'}) else: return jsonify({"code":400,"msg":'success'})
@app.route('/find_create_time', methods=['GET']) def find_create_time(): create_time = request.form.get('create_time') cursor.execute("select * from ms_information where create_time = %s",(create_time)) user = cursor.fetchone() if user: return jsonify({"code":200,"msg":'success'}) else: return jsonify({"code":400,"msg":'success'})
@app.route('/find_update_time', methods=['GET']) def find_update_time(): update_time = request.form.get('update_time') cursor.execute("select * from ms_information where update_time = %s",(update_time)) user = cursor.fetchone() if user: return jsonify({"code":200,"msg":'success'}) else: return jsonify({"code":400,"msg":'success'})
@app.route('/person_update',methods=['POST']) def person_update(): id = request.form.get('id') id_num = request.form.get('id_num') name = request.form.get('name') height = request.form.get('height') weight = request.form.get('weight') body_fat = request.form.get('body_fat') bmi = request.form.get('bmi') fitness_station = request.form.get('fitness_station') age = request.form.get('age') gender = request.form.get('gender') phone_number = request.form.get('phone_number') image = request.form.get('image') create_time = request.form.get('create_time') update_time = request.form.get('update_time')
cursor.execute("update physical_fitness set update_time =%s,height =%s,weight =%s,body_fat =%s,bmi =%s", (update_time, height, weight, body_fat, bmi)) cursor.execute( "update ms_information set id =%s,id_num =%s,name =%s,height =%s,weight =%s,body_fat =%s,bmi =%s,fitness_station =%s,age =%s,gender =%s,phone_number =%s,image =%s,create_time =%s,update_time =%s", ( id, id_num, name, height, weight, body_fat, bmi, fitness_station, age, gender, phone_number, image, create_time, update_time))
conn.commit()
return jsonify({"code": 200, "msg": 'success'})
@app.route('/personall_information', methods=['GET']) def personall_information(): cursor.execute("select * from ms_information") user = cursor.fetchone() if user: return jsonify({"code":200,"msg":'success'}) else: return jsonify({"code":400,"msg":'success'})
if __name__ == '__main__': app.run()
|