Esempio n. 1
0
 def upload_pic(pic, username):
     # 上传图片
     filename = 'static/resource/pic/' + username + SomeTool.current_date(
     ).replace(':', '-') + '.png'
     with open(
             filename,
             'wb',
     ) as file:
         file.write(pic)
     return filename
Esempio n. 2
0
 def post_update(db, version, content):
     cursor = db.cursor()
     sql = 'INSERT INTO update_list (version, content, created) VALUES ("{}", \'{}\', "{}")' \
           ''.format(version, str(content).replace('\'', '"'), SomeTool.current_date())
     cursor.execute(sql)
     cursor.close()
     try:
         db.commit()
         return True
     except:
         db.rollback()
         return False
Esempio n. 3
0
 def add_title(db, title, hidden, userId):
     # 添加分类
     cursor = db.cursor()
     sql = 'INSERT INTO title (title, userId, created, hidden) VALUES (\'{}\', {}, "{}", {})' \
           ''.format(str(title).replace('\'', '"'), userId, SomeTool.current_date(), hidden)
     cursor.execute(sql)
     cursor.close()
     try:
         db.commit()
         return True
     except:
         db.rollback()
         return False
Esempio n. 4
0
 def edit_content(db, contentId, head, titleId, content, hidden):
     cursor = db.cursor()
     created = SomeTool.current_date()
     sql = 'UPDATE content SET head = \'{}\', titleId = {}, content = \'{}\', hidden = {}, created = \'{}\' ' \
           'WHERE id = {}'.format(str(head).replace('\'', '"'), titleId, str(content).replace('\'', '"'), hidden, created, contentId)
     cursor.execute(sql)
     try:
         db.commit()
         sql = 'SELECT title FROM title WHERE id = {}'.format(titleId)
         cursor.execute(sql)
         results = list(cursor.fetchone())
         results.append(created)
         cursor.close()
         return results
     except:
         db.rollback()
         cursor.close()
         return False
Esempio n. 5
0
 def add_notice(db, content):
     cursor = db.cursor()
     sql = 'INSERT INTO notice (content, created) VALUES (\'{}\', "{}")'.format(str(content).replace('\'', '"'), SomeTool.current_date())
     cursor.execute(sql)
     cursor.close()
     try:
         db.commit()
         return True
     except:
         db.rollback()
         return False
Esempio n. 6
0
 def register(db, email, username, password):
     # 注册普通用户
     cursor = db.cursor()
     sql = 'INSERT INTO user ("email", "username", "password", "type", "created") VALUES ' \
           '("{}", "{}", "{}", "normal", "{}")'.format(email, username, SomeTool.key(password), SomeTool.current_date())
     cursor.execute(sql)
     cursor.close()
     try:
         db.commit()
         return MainTool.login(db, email, password)
     except:
         db.rollback()
         return False
Esempio n. 7
0
 def add_comment(db, contentId, email, comment):
     # 新增评论
     cursor = db.cursor()
     sql = 'INSERT INTO comment (email, comment, contentId, created, hidden) VALUES ' \
           '("{}", \'{}\', {}, "{}", 0)'.format(email, str(comment).replace('\'', '"'), contentId, SomeTool.current_date())
     cursor.execute(sql)
     cursor.close()
     try:
         db.commit()
         return True
     except:
         db.rollback()
         return False
Esempio n. 8
0
 def add_content(db, titleId, head, content, hidden):
     cursor = db.cursor()
     sql = 'INSERT INTO content (head, content, titleId, created, hidden) VALUES ' \
           '(\'{}\', \'{}\', \'{}\', \'{}\', {})' \
           ''.format(str(head).replace('\'', '"'), str(content).replace('\'', '"'), titleId, SomeTool.current_date(), hidden)
     print(sql)
     cursor.execute(sql)
     cursor.close()
     try:
         db.commit()
         return True
     except:
         db.rollback()
         return False