예제 #1
0
def delete_teacher():
    db = pymysql.connect(host="localhost",
                         user="******",
                         password="******",
                         db="face_recognition",
                         port=3306,
                         charset='utf8')
    cursor = db.cursor()
    sql = "SELECT t_id FROM teacher"
    cursor.execute(sql)
    t = cursor.fetchall()
    if request.method == "GET":
        return render_template("delete_teacher.html", t=t)
    else:
        teacher_id = request.form.get('teacher_id')
        print(teacher_id)
        sql = "DELETE FROM teacher WHERE t_id='%s'" % teacher_id
        try:
            cursor.execute(sql)
            db.commit()
        except:
            print('error')
            db.rollback()
        db.close()
        message = "删除教师数据成功"
        return render_template("index.html", message=message)
예제 #2
0
def select_teacher():
    db = pymysql.connect(host="localhost",
                         user="******",
                         password="******",
                         db="face_recognition",
                         port=3306,
                         charset='utf8')
    cursor = db.cursor()
    sql = "SELECT * FROM teacher"
    cursor.execute(sql)
    u = cursor.fetchall()
    db.close()
    return render_template('select_teacher.html', u=u)
예제 #3
0
def insert_teacher():
    message = "提示信息:"
    if request.method == 'GET':
        return render_template('insert_teacher.html', message=message)
    else:
        teacher_name = request.form.get('teacher_name')
        teacher_id = request.form.get('teacher_id')
        teacher_sex = request.form.get('teacher_sex')
        teacher_wx = request.form.get('teacher_wx')
        print(type(teacher_name))
        print(type(teacher_id))
        print(type(teacher_sex))
        print(type(teacher_wx))
        db = pymysql.connect(host="localhost",
                             user="******",
                             password="******",
                             db="face_recognition",
                             port=3306,
                             charset='utf8')
        cursor = db.cursor()
        sql = "SELECT t_id FROM teacher"
        cursor.execute(sql)
        result = cursor.fetchall()
        for i in result:
            print(i[0])
            if i[0] == teacher_id:
                message = message + "该工号教师已存在请重新插入"
                return render_template('insert_teacher.html', message=message)
        sql = "INSERT INTO teacher(t_name,t_id,t_sex,t_wx) VALUES ('%s','%s','%s','%s')" % (
            teacher_name, teacher_id, teacher_sex, teacher_wx)
        try:
            cursor.execute(sql)
            db.commit()
        except:
            db.rollback()
            print("error")
        db.close()
        message = "数据插入成功!"
        return render_template('index.html', message=message)
예제 #4
0
def alter_teacher():
    db = pymysql.connect(host="localhost",
                         user="******",
                         password="******",
                         db="face_recognition",
                         port=3306,
                         charset='utf8')
    cursor = db.cursor()
    sql = "SELECT t_id FROM teacher"
    cursor.execute(sql)
    t = cursor.fetchall()

    if request.method == "GET":
        return render_template("alter_teacher.html", t=t)
    else:
        teacher_id = request.form.get('teacher_id')
        alter_information = request.form.get('alter_information')
        information = request.form.get('information')
        if alter_information == "教师姓名":
            sql = "UPDATE teacher SET t_name='%s' WHERE t_id='%s'" % (
                information, teacher_id)
        elif alter_information == "教师微信id":
            sql = "UPDATE teacher SET t_wx='%s' WHERE t_id='%s'" % (
                information, teacher_id)
        elif alter_information == "教师性别":
            sql = "UPDATE teacher SET t_sex='%s' WHERE t_id='%s'" % (
                information, teacher_id)
        print(sql)
        try:
            cursor.execute(sql)
            db.commit()
        except:
            print('error')
            db.rollback()
        db.close()
        message = "修改教师信息成功"
        return render_template("index.html", message=message)
예제 #5
0
파일: app.py 프로젝트: Lucky-Ones/123
from flask import Flask,session,redirect
from flask import request,url_for,jsonify
from exts import cursor

import redis



from  exts import  db

import config
cur = db.cursor()

app = Flask(__name__)
app.config.from_object(config)



@app.route('/')
def hello_world():
    return 'Hello World!'


@app.route('/login', methods=['POST', 'GET'])
def login():

    if request.method == 'POST':
        xuehao = request.form['xuehao']
        password = request.form['password']
        sql = "select * from users WHERE xuehao = '%s'and password = '******'"
        try:
예제 #6
0
def clearresult1():
    a = []
    starttime = request.form.get('starttime')
    endtime = request.form.get('endtime')
    called_phone = request.form.get('called_phone')
    # session['datetime']=datetime
    # print(session['datetime'])
    db_host = "10.76.2.2"
    # db_port=3306
    db_user = "******"
    db_password = "******"
    db_data = "collect"
    # port=db_port,
    file_time = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time()))
    create_time = time.strftime('%Y-%m-%d %H:%M:%S',
                                time.localtime(time.time()))
    report_dir = r'C:\Python27\flask_test\diaozi1\record'
    # lists = os.listdir(report_dir)
    ##申明匿名函数 获取最新访问的文件
    # lists.sort(key=lambda fn: os.path.getatime(report_dir + '\\' + fn))
    # # 获取最新的文件
    # file = os.path.join(report_dir, lists[-1])
    db = pymysql.connect(host=db_host,
                         user=db_user,
                         passwd=db_password,
                         db=db_data,
                         charset="utf8")

    # wb = xlwt.Workbook(encoding='utf-8')  # 创建一个excel工作簿,编码utf-8,表格中支持中文
    # sheet = wb.add_sheet('sheet 1')  # 创建一个sheet
    cursor = db.cursor(cursor=pymysql.cursors.DictCursor)  # 创建一个指针对象
    # 查询SQL
    j = 0
    if starttime and endtime and called_phone:
        mySql = "SELECT * FROM  collect_soft_phone_event WHERE create_date > '%s'AND create_date<'%s'AND called_no='%s'" % (
            starttime, endtime, called_phone)
        cursor.execute(mySql)
        print(mySql)
        results = cursor.fetchall()
        if results:
            for i in results:
                record_file = i['record_file']
                if record_file:
                    a.append(record_file)
                    j += 1
            opt_df = pd.DataFrame(a)
        else:
            jsonify({"descraption": "没有查询对应的录音"})

    elif called_phone:
        Sql = "SELECT * FROM  collect_soft_phone_event WHERE called_no='%s'" % (
            called_phone)
        cursor.execute(Sql)
        print(Sql)
        results = cursor.fetchall()
        if results:
            for i in results:
                record_file = i['record_file']
                if record_file:
                    a.append(record_file)
                    j += 1

            opt_df = pd.DataFrame(a)
        else:
            jsonify({"descraption": "没有查询对应的录音"})
    else:
        return "未查到数据!请输入查询信息"
        # opt_df.to_sql("test_records", yconnect, if_exists='replace')

    if __name__ == '__main__':
        try:
            opt_df.to_excel(
                (report_dir + "/" + file_time + 'record' + '.' + "xlsx"))
        except Exception as e:
            pass

    print(j)
    return render_template('calender.html', url=a, status=j, time=create_time)