def jueseadd(): juese = request.args.get('name') roots = request.args.get('roots') cursor.execute("insert into role (rname,rinfo) values(%s,%s)", (juese, roots)) db.commit() return 'ok'
def ShiTi(): JD = request.args.get('JD') FX = request.args.get('FX') db1 = pymysql.connect(host="localhost", user="******", password="******", db="ribao1", cursorclass=pymysql.cursors.DictCursor, charset="utf8") cursor1 = db1.cursor() cursor1.execute("select pid from shijuan where fx=%s and jd=%s", (FX, JD)) res = cursor1.fetchall() str1 = '' pid = [] for item in range(len(res)): str1 += res[item]['pid'] + ',' pid.append(res[item]['pid']) str1 = str1[0:-1] pid = str1.split(",") # cursor.execute("select * from shiti where fangxiang=%s and jieduan=%s",(FX,JD)) cursor.execute( "select * from shiti where id=%s or id=%s or id=%s or id=%s or id=%s or id=%s or id=%s", (pid[0], pid[1], pid[2], pid[3], pid[4], pid[5], pid[6])) result = cursor.fetchall() db.commit() # print(result) return json.dumps(result)
def upload(): # file=request.files['file'] # file.save('1.xlsx') # book=xlrd.open_workbook("1.xlsx") # sheet=book.sheet_by_index(0) file_dir = os.path.join(basedir, app.config['UPLOAD_FOLDER']) if not os.path.exists(file_dir): os.makedirs(file_dir) f = request.files['file'] # 从表单的file字段获取文件,file为该表单的name值 if f and allowed_file(f.filename): # 判断是否是允许上传的文件类型 # fname = secure_filename(f.filename) # ext = fname.rsplit('.', 1)[1] # 获取文件后缀 # unix_time = int(time.time()) # new_filename = str(unix_time) + '.' + ext # 修改了上传的文件名 f.save(os.path.join(file_dir, 'kecheng.xlsx')) # 保存文件到upload目录 # token = base64.b64encode(new_filename) book = xlrd.open_workbook("url/upload/" + 'kecheng.xlsx') sheet = book.sheet_by_index(0) arr = [] for item in range(1, sheet.nrows): con = sheet.row_values(item) cursor.execute("insert into category (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.append((step[index], part[index], cid)) cursor.executemany( "insert into category_info (step,part,cid) values (%s,%s,%s)", (arr)) db.commit() return 'ok' else: return jsonify({"errno": 1001, "errmsg": "上传失败"})
def deljuese(): rid = request.args.get('rid') cursor.execute("delete from role where rid=%s", rid) db.commit() cursor.execute("select * from role") result = cursor.fetchall() return json.dumps(result)
def deluser(): id=request.args.get('id') cursor.execute("delete from user where id=%s",id) db.commit() cursor.execute("select * from user") result = cursor.fetchall() return json.dumps(result)
def extract_info(self, movie_soups): for movie_soup in movie_soups: #time.sleep(3) movie_detail_soup = self._get_soup( Spider.base_url + movie_soup.a['href']) movie = self._create_movie(movie_soup, movie_detail_soup) db.cursor.execute("SELECT COUNT(*) FROM movie WHERE source_id=\'{}\';".format(movie.source_id)) res = db.cursor.fetchone()[0] if res != 0: continue star_ids = self._process_stars( Spider.base_url + movie_soup.a['href']) if len(star_ids) == 0: continue movie_id = self._insert_entity(movie) self._insert_movie_stars(movie_id, star_ids) types = None for p in movie_soup.find_all("p"): if '类型' in p.text: types = [pa.text for pa in p.find_all('a')] if types is not None: for type_ in types: if self.type2id.get(type_, None) is None: db.cursor.execute( "INSERT INTO type (content) VALUE (\'{}\');".format(type_)) db.commit() db.cursor.execute( "SELECT id FROM type WHERE content=\'{}\';".format(type_)) idx = db.cursor.fetchone()[0] self.type2id.update({type_: idx}) idx = self.type2id[type_] movietype = MovieType(movie_id, idx) db.cursor.execute(movietype.sql) db.commit() time.sleep(3)
def seleclasses(): cursor.execute("select id,name from classes") result = cursor.fetchall() db.commit() for i in range(len(result)): result[i]['value'] = str(result[i].pop('id')) result[i]['label'] = result[i].pop('name') return json.dumps(result)
def seleKCS(): cursor.execute("select cid,cname from category") result = cursor.fetchall() db.commit() for i in range(len(result)): # print(result[i]) result[i]['value'] = str(result[i].pop('cid')) result[i]['label'] = result[i].pop('cname') return json.dumps(result)
def _insert_entity(self, entity): #print(entity.sql) db.cursor.execute(entity.sql) db.commit() sql = "SELECT id FROM {} WHERE source_id=\'{}\';".format( entity.table_name, entity.source_id) #print(sql) db.cursor.execute(sql) return db.cursor.fetchone()[0]
def findsame(): phone = request.args.get('phone') cursor.execute('select * from user where tel=%s', phone) result = cursor.fetchone() db.commit() if (result): return 'error' else: return 'ok'
def insertone(): name = request.args.get('name') start = request.args.get('start') end = request.args.get('ends') cid = request.args.get('cid') name=name.upper() cursor.execute("insert into classes (name,start,end,cid) values (%s,%s,%s,%s)",(name,start,end,cid)) db.commit() return 'ok'
def editjuese(): rid = request.args.get('rid') name = request.args.get('name') root = request.args.get('roots') cursor.execute("update role set rname=%s,rinfo=%s where rid=%s", (name, root, rid)) db.commit() print(rid, root, name) return "ok"
def uppShijuan(): FX=request.args.get("FX") JD=request.args.get("JD") TX=request.args.get("TX") Pid=request.args.get("pid") print(FX,JD,TX,Pid) cursor.execute("update shijuan set pid=%s where fx=%s and jd=%s and tx=%s",(Pid,FX,JD,TX)) db.commit() return 'ok'
def makeShijuan(): FX=request.args.get("FX") JD=request.args.get("JD") TX=request.args.get("TX") Pid=request.args.get("pid") cursor.execute("insert into shijuan (fx,jd,tx,pid) values (%s,%s,%s,%s)",(FX,JD,TX,Pid)) db.commit() print(FX,JD,TX,Pid) return 'ok'
def addJianda(): FX=request.args.get("FX") JD=request.args.get("JD") TiXing=request.args.get("TiXing") TiGan=request.args.get("TiGan") daan=request.args.get("daan") score=request.args.get("score") cursor.execute("insert into shiti (tigan,daan,types,fangxiang,jieduan,score) values(%s,%s,%s,%s,%s,%s)",(TiGan,daan,TiXing,FX,JD,score)) db.commit() return 'ok'
def chuli(con): arr = [] cursor.execute("insert into category (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.append((step[index], part[index], cid)) cursor.executemany( "insert into category_info (step,part,cid) values (%s,%s,%s)", (arr)) db.commit()
def updateOne(): id=request.args.get('id') name = request.args.get('name') start = request.args.get('start') end = request.args.get('ends') cid = request.args.get('cid') name = name.upper() # print(id,name,start,end,cid) cursor.execute("update classes set name=%s,start=%s,end=%s,cid=%s where id=%s", (name, start, end, cid, id)) db.commit() return 'ok'
def tijiaoribao(): ZYM = request.form['ZYM'] xinde = request.form['XinDe'] yijian = request.form['YiJian'] qita = request.form['QiTa'] con = request.form['con'] phone = '20181116996' print(type(con), con) cursor.execute( "insert into logs (phone,zym,workspace,yijian,xinde,qita) values (%s,%s,%s,%s,%s,%s)", (phone, ZYM, con, yijian, xinde, qita)) db.commit() return 'ok'
def seleClasses(): cid = request.args.get('cid') cursor.execute("select * from teacher where cid=%s", cid) result1 = cursor.fetchall() db.commit() for i in range(len(result1)): id = result1[i]['classid'] cursor.execute("select name,id from classes where id=%s", id) result2 = cursor.fetchone() result1[i]['banjiID'] = result2['id'] result1[i]['classid'] = result2['name'] # print(result1) return json.dumps(result1)
def insertOne(): name=request.args.get('name') tel=request.args.get('tel') school=request.args.get('school') sex=request.args.get('sex') banji=request.args.get('banji') rid='9' md5 = hashlib.md5() md5.update(b'123456') pswd = md5.hexdigest() cursor.execute("insert into user (name,tel,pass,rid) values(%s,%s,%s,%s)", (name,tel,pswd,rid)) cursor.execute("insert into students (name,phone,classid,sex,school) values (%s,%s,%s,%s,%s)",(name,tel,banji,sex,school)) db.commit() return 'ok'
def insertOne(): name=request.args.get("name") tel=request.args.get("tel") pswd=request.args.get("pass") md5 = hashlib.md5() md5.update(pswd.encode('utf8')) pswd = md5.hexdigest() roots=request.args.get("YH") cursor.execute('select rid from role where rinfo=%s', roots) result = cursor.fetchone() roots = result['rid'] cursor.execute("insert into user (name,tel,pass,rid) values(%s,%s,%s,%s)", (name, tel, pswd, roots)) db.commit() return 'ok'
def updausers(): uid = request.form["uid"] username = request.form['uname'] usertel = request.form['utel'] userpass = request.form['upass'] md5 = hashlib.md5() md5.update(userpass.encode('utf8')) userpass = md5.hexdigest() roots = request.form['roots'] cursor.execute('select rid from role where rinfo=%s', roots) result = cursor.fetchone() roots = result['rid'] cursor.execute("update user set name=%s,tel=%s,pass=%s,rid=%s where id=%s",(username,usertel,userpass,roots,uid)) db.commit() return 'ok'
def deleTea(): phone = request.args.get("phone") cursor.execute("delete from teacher where phone=%s", phone) cursor.execute("delete from user where tel=%s", phone) db.commit() cid = request.args.get('cid') cursor.execute("select * from teacher where cid=%s", cid) result1 = cursor.fetchall() for i in range(len(result1)): id = result1[i]['classid'] cursor.execute("select name,id from classes where id=%s", id) result2 = cursor.fetchone() result1[i]['banjiID'] = result2['id'] result1[i]['classid'] = result2['name'] db.commit() return json.dumps(result1)
def upload(): db1 = pymysql.connect(host="localhost", user="******", password="******", db="ribaoxitong", charset="utf8") cursor1 = db1.cursor() cursor1.execute("select name,id from classes") classes = cursor1.fetchall() db1.commit() classes = dict(classes) cursor1.execute("select cname,cid from category") kecheng = cursor1.fetchall() kecheng = dict(kecheng) cursor1.close() db1.close() file_dir = os.path.join(basedir, app.config['UPLOAD_FOLDER']) if not os.path.exists(file_dir): os.makedirs(file_dir) f = request.files['file'] # 从表单的file字段获取文件,file为该表单的name值 if f and allowed_file(f.filename): # 判断是否是允许上传的文件类型 f.save(os.path.join(file_dir, 'teachers.xlsx')) book = xlrd.open_workbook("url/upload/" + 'teachers.xlsx') sheet = book.sheet_by_index(0) user = [] tea = [] md5 = hashlib.md5() md5.update(b'123456') pw = md5.hexdigest() for item in range(1, sheet.nrows): # print(sheet.row_values(item)) con = (sheet.row_values(item)) single_user = [str(con[0]), str(int(con[1])), pw, 10] single_tea = [ str(con[0]), int(con[1]), kecheng[str(con[2]).upper()], classes[str(con[3]).upper()] ] user.append(single_user) tea.append(single_tea) cursor.executemany( "insert into user (name,tel,pass,rid) values(%s,%s,%s,%s)", (user)) cursor.executemany( "insert into teacher (name,phone,cid,classid) values(%s,%s,%s,%s)", (tea)) db.commit() return 'ok'
def insertOne(): name = request.args.get('name') tel = request.args.get('tel') banji = request.args.get('banji') FX = request.args.get('FX') name = name.upper() rid = '10' md5 = hashlib.md5() md5.update(b'123456') pswd = md5.hexdigest() cursor.execute("insert into user (name,tel,pass,rid) values(%s,%s,%s,%s)", (name, tel, pswd, rid)) cursor.execute( "insert into teacher (name,phone,cid,classid) values(%s,%s,%s,%s)", (name, tel, FX, banji)) db.commit() return 'ok'
def updateOne(): id = request.args.get('id') name = request.args.get('name') phone = request.args.get('tel') banji = request.args.get('banji') FX = request.args.get('FX') # print(id,name,phone,banji,FX) # name = name.upper() print(name, phone, id) cursor.execute("select * from user where tel=%s", phone) result = cursor.fetchone() tid = result['id'] print(tid) cursor.execute( "update teacher set name=%s,phone=%s,cid=%s,classid=%s where id=%s", (name, phone, FX, banji, id)) cursor.execute("update user set name=%s,tel=%s where id=%s", (name, phone, tid)) db.commit() return 'ok'
def upload(): db1 = pymysql.connect(host="localhost", user="******", password="******", db="ribaoxitong", charset="utf8") cursor1 = db1.cursor() cursor1.execute("select cname,cid from category") category=cursor1.fetchall() cursor1.close() db1.close() # print(category) category=dict(category) # print(category) file_dir = os.path.join(basedir, app.config['UPLOAD_FOLDER']) if not os.path.exists(file_dir): os.makedirs(file_dir) f = request.files['file'] # 从表单的file字段获取文件,file为该表单的name值 if f and allowed_file(f.filename): # 判断是否是允许上传的文件类型 # fname = secure_filename(f.filename) # ext = fname.rsplit('.', 1)[1] # 获取文件后缀 # unix_time = int(time.time()) # new_filename = str(unix_time) + '.' + ext # 修改了上传的文件名 f.save(os.path.join(file_dir, 'banji.xlsx')) book = xlrd.open_workbook("url/upload/" + 'banji.xlsx') sheet = book.sheet_by_index(0) shit = [] for item in range(1, sheet.nrows): # print(sheet.row_values(item)) arr=(sheet.row_values(item)) # arr[0]=int(arr[0]) arr[1]=category[arr[1]] arr[2]=xlrd.xldate_as_datetime(arr[2],0).strftime("%Y-%m-%d %H:%M:%S") arr[3]=xlrd.xldate_as_datetime(arr[3],0).strftime("%Y-%m-%d %H:%M:%S") # print(arr[0],arr[1],arr[2],arr[3]) shit.append((arr[0],arr[2],arr[3],arr[1])) # print(shit) cursor.executemany("insert into classes (name,start,end,cid) values(%s,%s,%s,%s)", (shit)) db.commit() return 'ok'
def updateOne(): uid = request.args.get("uid") name = request.args.get('name') tel = request.args.get('tel') pswd = request.args.get('pass') roots = request.args.get("YH") # uid = request.form['id'] # name=request.form['name'] # tel=request.form['tel'] # pswd=request.form['pass'] # roots=request.form['roots'] md5 = hashlib.md5() md5.update(pswd.encode('utf8')) pswd = md5.hexdigest() cursor.execute('select rid from role where rinfo=%s', roots) result = cursor.fetchone() roots = result['rid'] # print(uid,name,tel,pswd,roots) cursor.execute("update user set name=%s,tel=%s,pass=%s,rid=%s where id=%s", (name, tel, pswd, roots, uid)) db.commit() return 'ok'
def _insert_movie_stars(self, movie_id, star_ids): for star_id in star_ids: act = Act(star_id, movie_id) db.cursor.execute(act.sql) db.commit()