def delete(self): db = DB() cursor = db.connection() mysql = "delete from file where unique_id='%s'" % (self.unique_id) try: cursor.execute(mysql) db.db.commit() except: db.db.rollback() db.db.close()
def deleteallBycourseid(courseid): db = DB() cursor = db.connection() mysql = "delete from file where course_id='%s'" % (courseid) try: cursor.execute(mysql) db.db.commit() except: db.db.rollback() db.db.close()
def queryById(uid): db = DB() cursor = db.connection() mysql = "select * from file where unique_id='%s'" % (uid) result = None try: cursor.execute(mysql) result = cursor.fetchone() db.db.commit() except: db.db.rollback() db.db.close() return result
def query_all(self): db = DB() cursor = db.connection() mysql = "select * from file" try: cursor.execute(mysql) results = cursor.fetchall() db.db.commit() except: db.db.rollback() db.db.close() return results
def queryByurl(self, url): db = DB() cursor = db.connection() mysql = "select * from course where course_url='%s'" % (url) result = None try: cursor.execute(mysql) result = cursor.fetchone() db.db.commit() except: db.db.rollback() db.db.close() return result
def queryByuserid(self, name): db = DB() cursor = db.connection() mysql = "select * from teacher where user_id='%s'" % (name) result = None try: cursor.execute(mysql) result = cursor.fetchone() db.db.commit() except: db.db.rollback() db.db.close() return result
def insert(self): # 加载db类,用于连接数据库 db = DB() # 获取cursor cursor = db.connection() mysql="insert into teacher(unique_id,name,user_id,password,spare1,spare2,spare3,spare4)" \ " values('%s','%s','%s','%s','%s','%s','%s','%s')"\ %(self.unique_id,self.name,self.user_id,self.password,self.spare1,self.spare2,self.spare3,self.spare4) try: # 执行sql语句 cursor.execute(mysql) db.db.commit() except: db.db.rollback() db.db.close()
def update(self): db = DB() cursor = db.connection() mysql = "update file set file_name='%s',file_url='%s',course_id='%s',upload_time='%s',week_no='%s',spare2='%s',\ spare3='%s',spare4='%s' where unique_id='%s'" % ( self.file_name, self.file_url, self.course_id, self.upload_time, self.week_no, self.spare2, self.spare3, self.spare4, self.unique_id) try: cursor.execute(mysql) db.db.commit() except: db.db.rollback() db.db.close()
def query_allByteacher(self, teacher): db = DB() cursor = db.connection() print("teacher:", teacher) mysql = "select * from course where teacher='%s'" % (teacher) results = None try: cursor.execute(mysql) results = cursor.fetchall() db.db.commit() except: db.db.rollback() db.db.close() return results
def update(self): db = DB() cursor = db.connection() mysql = "update course set course_url='%s',name='%s',description='%s',teacher='%s',spare1='%s',spare2='%s',\ spare3='%s',spare4='%s' where unique_id='%s'" % ( self.course_url, self.name, self.description, self.teacher, self.spare1, self.spare2, self.spare3, self.spare4, self.unique_id) try: cursor.execute(mysql) db.db.commit() except: db.db.rollback() db.db.close()
def insert(self): # 加载db类,用于连接数据库 db = DB() # 获取cursor cursor = db.connection() mysql="insert into course(unique_id,course_url,name,description,teacher,spare1,spare2,spare3,spare4)" \ " values('%s','%s','%s','%s','%s','%s','%s','%s','%s')"\ %(self.unique_id,self.course_url,self.name,self.description,self.teacher,self.spare1,self.spare2,self.spare3,self.spare4) print(mysql) try: # 执行sql语句 cursor.execute(mysql) db.db.commit() except: db.db.rollback() db.db.close()
def update(self): db = DB() cursor = db.connection() mysql = "update teacher set name='%s',user_id='%s',password='******',spare1='%s',spare2='%s',\ spare3='%s',spare4='%s' where unique_id='%s'" % ( self.name, self.user_id, self.password, self.spare1, self.spare2, self.spare3, self.spare4, self.unique_id) try: cursor.execute(mysql) db.db.commit() except: db.db.rollback() db.db.close()
def insert(self): # 加载db类,用于连接数据库 db = DB() # 获取cursor cursor = db.connection() mysql = "insert into file(unique_id,file_name,file_url,course_id,upload_time,week_no,spare2,spare3,spare4)" \ " values('%s','%s','%s','%s','%s','%s','%s','%s','%s')" \ % (self.unique_id, self.file_name, self.file_url, self.course_id, self.upload_time, self.week_no, self.spare2, self.spare3, self.spare4) print("Mysql:",mysql) try: # 执行sql语句 cursor.execute(mysql) db.db.commit() print("insert sucess") except: db.db.rollback() print("insert failure") db.db.close()
import os from datetime import datetime, time, date, timedelta from flask import Flask, request, jsonify, render_template, make_response, send_from_directory, redirect from module.db import DB app = Flask(__name__) db = DB() @app.route('/favicon.ico') def favicon(): return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon.ico', mimetype='image/vnd.microsoft.icon') @app.route('/.well-known/acme-challenge/<txt>') def set_ssl(txt): if txt == '3vwW5SRgZt4AEFehEHc84GFSUOusbDxGy9ttvB196t0' or txt == 'G-VR5cUD3SMMLSkyhWVENSCV5ho9sjv8bAp-w_CT2ic': return txt+".N-8jdkqRBuf94BntZAldJXTCCX8-v1FUXWikPKxD_LY" else: return redirect('/') @app.errorhandler(404) def page_not_found(error): return render_template('404.html') @app.route('/') def index(): return render_template('index.html') @app.route('/delete_record_by_admin') def delete_record_by_admin(): id = request.args.get('id', '')