def register(self, user_wx_id): db = DBconnect.DBconnect() new_user_id = str(random.randint(0, 99999999)).zfill(8) bool_is_already = self.__is_already(db, new_user_id) while bool_is_already: new_user_id = str(random.randint(0, 99999999)).zfill(8) bool_is_already = self.__is_already(db, new_user_id) # 插入数据库 # userName 暂时和 userId 相同,这样只是为了让微信用户快速注册 # userPwd 暂时设置为 123456 # 对于新用户而言 已经回答的正确数 为 0,错误题目数也为0 temp_pwd = "123456" args = (new_user_id, new_user_id, temp_pwd, user_wx_id, 0, 0) is_successful = db.dbInsert("user_info", new_user_id, new_user_id, temp_pwd, user_wx_id, 0, 0) if is_successful: dic = { "returnCode": "a0", "user_id": new_user_id, "user_name": new_user_id, "user_pwd": temp_pwd, "user_wx_id": user_wx_id, "user_rightAnswer": "0", "user_wrongAnswer": "0" } else: dic = {"returnCode": "r0"} return dic
def __is_already(self, db, user_id): db = DBconnect.DBconnect() info = db.dbQuery_user_is_already(user_id) if info == None: return False else: return True
def get_title(self, chp_id): dbTable = "titlenumber_info" db = DBconnect.DBconnect() info = db.dbQuery_title_according_to_chapter(str(chp_id)) dic = {} for i in range(0, len(info)): pageNumber = "t" + str(i + 1) dic_tmp = { "title_id": info[i][0], # 章节编号 "chapters_id": info[i][1], # 属于哪本书的编号 } dic.setdefault(pageNumber, dic_tmp) return dic
def get_chapter(self, sub_id): dbTable = "chapters_info" db = DBconnect.DBconnect() info = db.dbQuery_chapter_according_to_subject(str(sub_id)) dic = {} for i in range(0, len(info)): pageNumber = "c" + str(i + 1) dic_tmp = { "chapters_id": info[i][0], # 章节编号 "subject_id": info[i][1], # 属于哪本书的编号 "chapters_name": info[i][2] # 该章节中文名称 } dic.setdefault(pageNumber, dic_tmp) return dic
def get_subject(self): dbTable = "subject_info" db = DBconnect.DBconnect() info = db.dbQuery(dbTable) dic = {} for i in range(0, len(info)): pageNumber = "s" + str(i + 1) dic_tmp = { "subject_id": info[i][0], # 书本<科目>编号 "subject_name": info[i][1], # 书本<科目>名称 "subject_brief": info[i][2] # 书本<科目>介绍 } dic.setdefault(pageNumber, dic_tmp) return dic
def get_chapter_all(self): dbTable = "chapters_info" db = DBconnect.DBconnect() info = db.dbQuery(dbTable) dic = {} for i in range(0, len(info)): #题目编号我不希望从0开始 pageNumber = "c" + str(i + 1) dic_tmp = { "chapters_id": info[i][0], # 章节编号 "subject_id": info[i][1], # 属于哪本书的编号 "chapters_name": info[i][2] # 该章节中文名称 } dic.setdefault(pageNumber, dic_tmp) return dic
def get_Chapter(self): dbTable = "chapters_info" db = DBconnect.DBconnect() info = db.dbQuery(dbTable) dic = {} for i in range(0, len(info)): pageNumber = "p" + str(i) dic_tmp = { "chapter_no": info[i][0], # 章节编号 "chapter_from": info[i][1], # 属于哪本书的编号 "chapter_info": info[i][2] # 该章节中文名称 } print(pageNumber) dic.setdefault(pageNumber, dic_tmp) return dic
def check_login(self, user_id, user_pwd, user_wx_id): db = DBconnect.DBconnect() info = db.dbQuery_userLogin(user_id, user_pwd) if info == None: dic = {"returnCode": "r0"} else: dic = { "returnCode": "a0", "user_id": info[0], "user_name": info[1], "user_wx_id": info[3], "user_accuracy": info[4] } print(dic) return dic
def get_title_info(self, tit_id): dbTable = "title_info" db = DBconnect.DBconnect() info = db.dbQuery_title_according_to_title(str(tit_id)) dic = {} for i in range(0, len(info)): pageNumber = "t" + str(i + 1) dic_tmp = { "title_id": info[i][0], "titleHead": info[i][1], "titleCont": info[i][2], "titleAnswer": info[i][3], "titleAnalysis": info[i][4], "titleAveracc": info[i][5], "titlespaper": info[i][6], "specialNote": info[i][7], } dic.setdefault(pageNumber, dic_tmp) return dic
def answerCorrectJudgment(self, user_id, tit_id, answer, user_note): # 先提取题号对应的题目信息 # 再将输入的答案与实际答案进行对比 # 最后根据用户请求写入user_info表中生成总数据记录 # 再将数据写入titlenote_info表中做详细记录 # 最后返回True or False表示回答正确与否 dbTable = "titlenote_info" db = DBconnect.DBconnect() info = db.dbQuery_title_according_to_title(str(tit_id)) rightAnswer = info[0][3] print(answer, rightAnswer) isRight = False inpRight = "0" if str(answer) == str(rightAnswer): isRight = True inpRight = "1" # 更新用户回答总信息 db.dbUpdate_user_answer(isRight, user_id) # 更新用户回答详细内容 - 记录题号和回答时间 inputDataTime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") db.dbInsert(dbTable, user_id, tit_id, inpRight, inputDataTime, user_note) return isRight
def get_title_len(self): dbTable = "title_info" db = DBconnect.DBconnect() info = db.dbQuery_title_len(dbTable) return info