Ejemplo n.º 1
0
def get_by_id():
    print(request.data)
    data = json.loads(request.data)
    print(data)
    paperId = data["paperId"]
    sql = "select * from teacher_paper where paperId = '%s'" % (paperId)
    print(sql)
    try:
        db2 = pymysql.connect(host="localhost", user="******", password="******",
                              db="ebook", port=3306, use_unicode=True, charset="utf8mb4")
        cursor = db2.cursor()
        cursor.execute(sql)
        all_data = cursor.fetchall()
        print("all", all_data)
        key_list = ["paperId", "paperName", "paperDescription",
                    "selectContent", "askContent", "createTime", "creator"]
        resp_data = tuple_to_dict(key_list, all_data)
        print("resp", resp_data)
        resp = do_response("success", resp_data, 200)
    except Exception as e:
        print(e)
        data = str(e)
        resp = do_response("error", data, 400)

    cursor.close()
    db2.close()
    return make_response(resp, 200)
Ejemplo n.º 2
0
def get_all():
    sql = 'select * from paper_question'
    print(sql)
    try:
        db2 = pymysql.connect(host="localhost",
                              user="******",
                              password="******",
                              db="ebook",
                              port=3306,
                              use_unicode=True,
                              charset="utf8mb4")
        cursor = db2.cursor()
        cursor.execute(sql)
        all_data = cursor.fetchall()
        print("all", all_data)
        key_list = [
            "questionId", "questionName", "questionContent", "creator",
            "createTime", "questionType"
        ]
        resp_data = tuple_to_dict(key_list, all_data)
        print("resp", resp_data)
        resp = do_response("success", resp_data, 200)

    except Exception as e:
        print(e)
        data = str(e)
        resp = do_response("error", data, 400)

    cursor.close()
    db2.close()
    return make_response(resp, 200)
Ejemplo n.º 3
0
def getClass():
    print("data",request.data)
    print("sss")
    data = json.loads(request.data)
    print(data)
    teacherName = data['teacherName']
    sql = 'select * from class_teacher where teacherName = "%s"' % (teacherName)
    if teacherName == "":
        sql = 'select * from class_teacher'
    print(sql)
    try:
        db2 = pymysql.connect(host="localhost",user="******",password="******",db="ebook",port=3306,use_unicode=True, charset="utf8mb4")
        cursor =db2.cursor()
        cursor.execute(sql)
        print("ssss")
        all_data = cursor.fetchall()
        print("all",all_data)
        key_list = ["className", "teacherName", "description"]
        resp_data = tuple_to_dict(key_list, all_data)
        print("resp",resp_data)
        resp = do_response("success",resp_data, 200)
        cursor.close()
        db2.close()
    except Exception as e:
        print(e)
        data = str(e)
        resp = do_response("error", data, 400)
        
    return make_response(resp, 200)
Ejemplo n.º 4
0
def student_paper():
    print(request.data)
    data = json.loads(request.data)
    print(data)
    studentName = data["studentName"]
    sql = "select stuPaperId,studentName,a.paperId,a.askContent, a.selectContent,a.createTime,score,remark,status, b.paperName,b.paperDescription from student_paper a left join teacher_paper b on a.paperId = b.paperId where a.studentName = '%s' \
                    order by createTime desc" % (studentName)
    print(sql)
    try:
        db2 = pymysql.connect(host="localhost", user="******", password="******",
                              db="ebook", port=3306, use_unicode=True, charset="utf8mb4")
        cursor = db2.cursor()
        cursor.execute(sql)
        all_data = cursor.fetchall()
        print("all", all_data)
        key_list = ["stuPaperId", "studentName", "paperId",
                    "askContent", "selectContent", "createTime", "score", "remark", "status", "paperName", "paperDescription"]
        resp_data = tuple_to_dict(key_list, all_data)
        print("resp", resp_data)
        resp = do_response("success", resp_data, 200)
    except Exception as e:
        print(e)
        data = str(e)
        resp = do_response("error", data, 400)

    cursor.close()
    db2.close()
    return make_response(resp, 200)
Ejemplo n.º 5
0
def get_class_one():
    print(request.data)
    data = json.loads(request.data)
    print(data)
    className = data['className']
    sql = ''' select studentName from class_student where className = "%s" \
                and status = 1''' % (className)
    print(sql)
    try:
        db2 = pymysql.connect(host="localhost",user="******",password="******",db="ebook",port=3306,use_unicode=True, charset="utf8mb4")
        cursor =db2.cursor()
        cursor.execute(sql)
        print(sql)
        all_data = cursor.fetchall()
        print("all",all_data)
        key_list = ["studentName"]
        resp_data = tuple_to_dict(key_list, all_data)
        print("resp",resp_data)
        resp = do_response("success",resp_data, 200)
        cursor.close()
        db2.close()
    except Exception as e:
        print(e)
        data = str(e)
        resp = do_response("error", data, 400)
        
    return make_response(resp, 200)
Ejemplo n.º 6
0
def addClassNotificatio():
    print(request.data)
    data = json.loads(request.data)
    print(data)
    className = data['className']
    sql = 'select * from class_notification where className = "%s"' %(className)
    print(sql)
    try:
        db2 = pymysql.connect(host="localhost",user="******",password="******",db="ebook",port=3306,use_unicode=True, charset="utf8mb4")
        cursor =db2.cursor()
        cursor.execute(sql)
        print(sql)
        all_data = cursor.fetchall()
        print("all",all_data)
        key_list = ["notificationId","className","title","content","noticeTime"]
        resp_data = tuple_to_dict(key_list, all_data)
        print("resp",resp_data)
        resp = do_response("success",resp_data, 200)
        cursor.close()
        db2.close()
    except Exception as e:
        print(e)
        data = str(e)
        resp = do_response("error", data, 400)

    return make_response(resp, 200)
Ejemplo n.º 7
0
def get_join_list():
    print(request.data)
    data = json.loads(request.data)
    print(data)
    studentName = data['studentName']
    sql = 'select a.className,a.teacherName, a.description, b.status \
        from class_teacher as a left join class_student as b \
            on a.className = b.className \
                and b.studentName = "%s"' % (studentName)
    print(sql)
    try:
        db2 = pymysql.connect(host="localhost",user="******",password="******",db="ebook",port=3306,use_unicode=True, charset="utf8mb4")
        cursor =db2.cursor()
        cursor.execute(sql)
        print(sql)
        all_data = cursor.fetchall()
        print("all",all_data)
        key_list = ["className", "teacherName", "description", "status"]
        resp_data = tuple_to_dict(key_list, all_data)
        print("resp",resp_data)
        resp = do_response("success",resp_data, 200)
        cursor.close()
        db2.close()
    except Exception as e:
        print(e)
        data = str(e)
        resp = do_response("error", data, 400)

    return make_response(resp, 200)
Ejemplo n.º 8
0
def get_bbs_comment_by_topic():
    print(request.data)
    data = json.loads(request.data)
    print(data)
    bbsId = data['bbsId']
    sql = 'select * from bbs_comment where bbsId = %d order by createTime asc' \
        % (int(bbsId))
    print(sql)
    try:
        db2 = pymysql.connect(host="localhost",user="******",password="******",db="ebook",port=3306,use_unicode=True, charset="utf8mb4")
        cursor =db2.cursor()
        cursor.execute(sql)
        all_data = cursor.fetchall()
        print("all",all_data)
        key_list = ["commentId","bbsId","author","avatar","content","createTime"]
        resp_data = tuple_to_dict(key_list, all_data)
        print("resp",resp_data)
        resp = do_response("success",resp_data, 200)
        cursor.close()
        db2.close()
    except Exception as e:
        print(e)
        data = str(e)
        resp = do_response("error", data, 400)

    return make_response(resp, 200)
Ejemplo n.º 9
0
def searchBook():
    print(request.data)
    data = json.loads(request.data)
    print(data)
    searchKey = data["searchKey"]
    sql = "select * from ebook where concat(title, author,createTime) like '%%%s%%' order by createTime asc" % searchKey
    print(sql)
    try:
        db2 = pymysql.connect(host="localhost",
                              user="******",
                              password="******",
                              db="ebook",
                              port=3306,
                              use_unicode=True,
                              charset="utf8mb4")
        cursor = db2.cursor()
        cursor.execute(sql)
        all_data = cursor.fetchall()
        print("all", all_data)
        key_list = ["ebookId", "title", "author", "createTime", "contentHtml"]
        resp_data = tuple_to_dict(key_list, all_data)
        print("resp", resp_data)
        resp = do_response("success", resp_data, 200)
        cursor.close()
        db2.close()
    except Exception as e:
        print(e)
        data = str(e)
        resp = do_response("error", data, 400)

    return make_response(resp, 200)
Ejemplo n.º 10
0
def get_book_list():
    # print(request.data)
    # data = json.loads(request.data)
    # print(data)
    # askContent = data["askContent"]
    # createTime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    # sql = "insert into teacher_paper(paperName, paperDescription, \
    #         selectContent, askContent, createTime, creator) \
    #             values('%s','%s','%s','%s','%s','%s') "  % \
    #                 (paperName, paperDescription,selectContent, \
    #                      askContent, createTime, creator)
    sql = "select * from ebook order by createTime asc"
    print(sql)
    try:
        db2 = pymysql.connect(host="localhost",
                              user="******",
                              password="******",
                              db="ebook",
                              port=3306,
                              use_unicode=True,
                              charset="utf8mb4")
        cursor = db2.cursor()
        cursor.execute(sql)
        all_data = cursor.fetchall()
        print("all", all_data)
        key_list = ["ebookId", "title", "author", "createTime", "contentHtml"]
        resp_data = tuple_to_dict(key_list, all_data)
        print("resp", resp_data)
        resp = do_response("success", resp_data, 200)
        cursor.close()
        db2.close()
    except Exception as e:
        print(e)
        data = str(e)
        resp = do_response("error", data, 400)

    return make_response(resp, 200)
Ejemplo n.º 11
0
def load_book():
    print(request.data)
    data = json.loads(request.data)
    print(data)
    ebookId = data["ebookId"]
    username = data["username"]
    sql = "select * from ebook_note where ebookId = %d and username \
                = '%s'" % (ebookId, username)
    print(sql)
    try:
        db2 = pymysql.connect(host="localhost",
                              user="******",
                              password="******",
                              db="ebook",
                              port=3306,
                              use_unicode=True,
                              charset="utf8mb4")
        cursor = db2.cursor()
        cursor.execute(sql)
        all_data = cursor.fetchall()
        print("all", all_data)
        key_list = [
            "noteId", "ebookId", "username", "contentHtml", "createTime",
            "updateTime"
        ]
        resp_data = tuple_to_dict(key_list, all_data)
        print("resp", resp_data)
        resp = do_response("success", resp_data, 200)
        cursor.close()
        db2.close()
    except Exception as e:
        print(e)
        data = str(e)
        resp = do_response("error", data, 400)

    return make_response(resp, 200)