Example #1
0
def filedata(con):
    cur.execute("insert into `cursor` (cname) values (%s)", (con[0]))
    cid = db.insert_id()
    step = con[1].split("\n")
    part = con[2].split("\n")
    for index in range(len(step)):
        arr = []
        arr.append((step[index], part[index], cid))
        cur.executemany(
            "insert into `dircursor` (step,part,cid) values (%s,%s,%s)", (arr))
        db.commit()
Example #2
0
def upload1():
    UPLOAD_FOLDER = 'upload/teacher/'
    current_app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
    if request.method == 'POST':
        db1 = pymysql.connect(host="localhost",
                              user="******",
                              password="******",
                              db="lzm",
                              charset="utf8")
        cur1 = db1.cursor()
        cur1.execute("select cname,cid from `cursor`")
        c = dict(cur1.fetchall())
        db1.close()
        f = request.files['file']  # 从表单的file字段获取文件,myfile为该表单的name值
        if f and allowed_file(f.filename):  # 判断是否是允许上传的文件类型
            fname = secure_filename(f.filename)
            suf = fname.rsplit('.', 1)[1]  #截取文件后缀名
            now = int(time.time())
            newfile = str(now) + '.' + suf
            f.save(os.path.join(current_app.config['UPLOAD_FOLDER'], newfile))
            book = xlrd.open_workbook('upload/teacher/' + newfile)
            sheet = book.sheet_by_index(0)  #定义一个对象
            arr = []
            user = []
            for i in range(1, sheet.nrows):
                con = sheet.row_values(i)
                if isinstance(con[1], float):
                    con[1] = str(int(con[1]))
                if isinstance(con[3], float):
                    con[3] = int(con[3])
                con[2] = c[con[2]]
                arr.append(con)

                name = con[0]
                phone = con[1]
                md5 = hashlib.md5()
                md5.update(b'111111')
                up = md5.hexdigest()
                arr1 = [name, phone, up, phone, 2]
                user.append(arr1)
            cur.executemany(
                "insert into teacher (name,phone,fid,class) values (%s,%s,%s,%s)",
                (arr))
            cur.executemany(
                "insert into users (name,uname,upass,phone,rid) values (%s,%s,%s,%s,%s)",
                (user))
            db.commit()
            return 'ok'
        else:
            return "error"
Example #3
0
def editonecursor():
    data = request.args.get('data')
    data = json.loads(data)
    print(data)
    cid = request.args.get('id')
    cur.execute("update `cursor` set cname=%s where cid=%s", (data[0], cid))
    cur.execute("delete from dircursor  where cid=%s", (cid))
    step = data[1].split("\n")
    part = data[2].split("\n")
    for index in range(len(step)):
        arr = []
        arr.append((step[index], part[index], cid))
        cur.executemany(
            "insert into `dircursor` (step,part,cid) values (%s,%s,%s)", (arr))
    db.commit()
    return 'ok'
Example #4
0
def upload():
    UPLOAD_FOLDER = 'upload/exam/'
    current_app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
    if request.method == 'POST':
        f = request.files['file']  # 从表单的file字段获取文件,myfile为该表单的name值
        if f and allowed_file(f.filename):  # 判断是否是允许上传的文件类型
            fname = secure_filename(f.filename)
            suf = fname.rsplit('.', 1)[1]     #截取文件后缀名
            now = int(time.time())
            newfile = str(now)+'.'+suf
            f.save(os.path.join(current_app.config['UPLOAD_FOLDER'],newfile))
            book=xlrd.open_workbook('upload/exam/'+newfile)
            sheet = book.sheet_by_index(0)   #定义一个对象
            question=[]
            for i in range(1,sheet.nrows):
                arr=[]
                con = sheet.row_values(i)
                cur.execute("select cid from `cursor` where cname=%s",(con[0]))
                fid=cur.fetchone()['cid']
                cur.execute("select nid from questiontype where name=%s", (con[1]))
                nid=cur.fetchone()['nid']
                sel=con[3].split('|')
                if nid==1:
                    answer=sel.index(str(int(con[4])))
                elif nid==2:
                    answer=''
                    ans = con[4].split('|')
                    for i in range(len(sel)):
                        for j in range(len(ans)):
                            if sel[i] == ans[j]:
                                a=str(i)+'|'
                                answer+=a
                    answer=answer[0:-1]
                elif nid==3:
                    con[3]=None
                    if con[4]=='错':
                        answer=0
                    elif con[4]=='对':
                        answer=1
                arr+=[fid]+[con[2]]+[con[3]]+[answer]+[int(con[5])]+[nid]
                question.append(tuple(arr))

            cur.executemany("insert into question (fid,con,`option`,answer,point,nid) values (%s,%s,%s,%s,%s,%s)",(question))
            db.commit()
            return 'ok'
        else:
            return "error"
Example #5
0
def selectdaily():
    rid = session.get('rid')
    uid = session.get('uid')
    if rid == '1':
        cur.execute("select name,date from studaily where uid=%s", (uid))
        result = cur.fetchall()
        for item in result:
            # 把时间对象转化为字符串
            if isinstance(item['date'], object):
                item['date'] = item['date'].strftime("%Y-%m-%d")
        return json.dumps(result)
    elif rid == '2':
        cur.execute("select phone from users where uid=%s", (uid))
        phone = cur.fetchone()['phone']
        cur.execute("select class from teacher where phone=%s", (phone))
        classname = cur.fetchone()['class']
        cur.execute("select id from classes where name=%s", (classname))
        id = cur.fetchone()['id']
        db1 = pymysql.connect(host="localhost",
                              user="******",
                              password="******",
                              db="lzm",
                              charset="utf8")
        cur1 = db1.cursor()
        cur1.execute('select phone from studentes where calssid=%s', (id))
        allphone = cur1.fetchall()
        print(allphone)
        cur1.executemany('select uid from users where phone=%s', (allphone))
        alluid = cur1.fetchall()
        db1.close()
        cur.executemany('select * from studaily where uid=%s', (alluid))
        result = cur.fetchall()
        for item in result:
            if isinstance(item['date'], object):
                item['date'] = item['date'].strftime("%Y-%m-%d")
        return json.dumps(result)
    else:
        cur.execute("select * from studaily")
        result = cur.fetchall()
        for item in result:
            # 把时间对象转化为字符串
            if isinstance(item['date'], object):
                item['date'] = item['date'].strftime("%Y-%m-%d")
        return json.dumps(result)
Example #6
0
def upload1():
    UPLOAD_FOLDER = 'upload/classes/'
    current_app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
    if request.method == 'POST':
        db1 = pymysql.connect(host="localhost",
                              user="******",
                              password="******",
                              db="lzm",
                              charset="utf8")
        cur1 = db1.cursor()
        cur1.execute("select cname,cid from `cursor`")
        c = dict(cur1.fetchall())
        db1.close()
        f = request.files['file']  # 从表单的file字段获取文件,myfile为该表单的name值
        if f and allowed_file(f.filename):  # 判断是否是允许上传的文件类型
            fname = secure_filename(f.filename)
            suf = fname.rsplit('.', 1)[1]  #截取文件后缀名
            now = int(time.time())
            newfile = str(now) + '.' + suf
            f.save(os.path.join(current_app.config['UPLOAD_FOLDER'], newfile))
            book = xlrd.open_workbook('upload/classes/' + newfile)
            sheet = book.sheet_by_index(0)  #定义一个对象
            arr = []
            for i in range(1, sheet.nrows):
                con = sheet.row_values(i)
                if isinstance(con[0], float):
                    con[0] = int(con[0])
                con[2] = xlrd.xldate_as_datetime(
                    con[2], 0).strftime("%Y-%m-%d %H:%M:%S")
                con[3] = xlrd.xldate_as_datetime(
                    con[3], 0).strftime("%Y-%m-%d %H:%M:%S")
                con[1] = c[con[1]]
                arr.append(con)
            cur.executemany(
                "insert into classes (name,fid,start,end) values (%s,%s,%s,%s)",
                (arr))
            db.commit()
            return 'ok'
        else:
            return "error"