def getBookInfo(id): db = getdb() cursor = db.cursor(DictCursor) sql = "select * from book where id='%s'" % id cursor.execute(sql) res = cursor.fetchone() return res
def get_managers(): db = getdb() cursor = db.cursor() field_list = ['id', 'username', 'passwd'] sql = "select %s from manager where valid='true'" % ', '.join(field_list) cursor.execute(sql) res = cursor.fetchall() return res
def change_password(passwd): m2 = hashlib.md5() m2.update(passwd.encode('utf-8')) md5_passwd = m2.hexdigest() sql = "update manager set passwd='%s'" % md5_passwd db = getdb() cursor = db.cursor() cursor.execute(sql) db.commit()
def user_delete(): id = request.args.get('id', None) if id is None: return redirect('/admin/user/list') db = getdb() cursor = db.cursor() sql = "update user set valid='0' where id = '%s'" % id cursor.execute(sql) db.commit() return render_template('admin/user_delete.html')
def runSql(self, sql): print(sql) db = getdb() cursor = db.cursor() try: cursor.execute(sql) db.commit() except: db.rollback() cursor.close() db.close()
def get_user_one(id): db = getdb() cursor = db.cursor() fields = ['id', 'username', 'nickname', 'email', 'phone', 'passwd'] sql = "select %s from user" % ', '.join(fields) sql += " where valid='1' limit 1" cursor.execute(sql) userInfo = cursor.fetchone() if userInfo is None: return None print(userInfo) res = dict(zip(fields, userInfo)) return res
def login_valid(username, passwd): db = getdb() cursor = db.cursor() sql_find_user = "******" % ( username, passwd) print(sql_find_user) cursor.execute(sql_find_user) res = cursor.fetchone()[0] print(res) if int(res) != 0: return True else: return False
def login_valid(username, passwd): db = getdb() cursor = db.cursor() m2 = hashlib.md5() m2.update(passwd.encode('utf-8')) md5_passwd = m2.hexdigest() sql_find_user = "******" % ( username, md5_passwd) print(sql_find_user) cursor.execute(sql_find_user) res = cursor.fetchone()[0] print(res) if int(res) == 1: return True else: return False
def book_delete(id): id = int(id) db = getdb() cursor = db.cursor() sql = "update book set valid=0 where id='%d'" % int(id) try: cursor.execute(sql) db.commit() cursor.close() db.close() return 1 except: db.rollback() cursor.close() db.close() return 0
def do_register(request): fields = ['username', 'nickname', 'passwd', 'email', 'phone'] keys = ', '.join(fields) values = ','.join(map(lambda x: '"%s"' % request.form.get(x, ''), fields)) sql = "insert into user(%s) values (%s)" % (keys, values) print(sql) db = getdb() cursor = db.cursor() try: cursor.execute(sql) db.commit() db.close() return True except: db.rollback() db.close() return False
def getbooks(page_num=1, page_size=20, come_from=None, order=None): db = getdb() cursor = db.cursor(DictCursor) page_num = int(page_num) start = (page_num - 1) * page_size sql = "select id, bookname, link, come_from, author, price, grade from book" if come_from is not None: sql += " where come_from='%s' " sql += " limit %d, %d" % (start, page_size) print(sql) cursor.execute(sql) data = cursor.fetchall() sql = "select count(*) as cnt from book" if come_from is not None: sql += " where come_from='%s'" cursor.execute(sql) count = cursor.fetchone()['cnt'] return data, count
def get_users(page_num=1, page_size=20): db = getdb() cursor = db.cursor(DictCursor) page_num = int(page_num) start = (page_num - 1) * page_size field_list = ['id', 'username', 'nickname', 'email', 'phone', 'passwd'] sql = "select %s from user" % ', '.join(field_list) sql += " where valid='1'" sql += " limit %d, %d" % (start, page_size) cursor.execute(sql) data = cursor.fetchall() cursor.close() cursor = db.cursor() sql = "select count(*) from user" sql += " where valid='1'" cursor.execute(sql) count = cursor.fetchone()[0] return data, count
def change_valid(cur_passwd, passwd, confirm): if cur_passwd == '' or passwd == '' or confirm == '': return False db = getdb() cursor = db.cursor() m2 = hashlib.md5() m2.update(cur_passwd.encode('utf-8')) md5_passwd = m2.hexdigest() sql_find_user = "******" % md5_passwd print(sql_find_user) cursor.execute(sql_find_user) res = cursor.fetchone()[0] print(res) if int(res) == 0: return False if passwd == confirm: return True else: return False
def __init__(self): self.db = getdb() self.cursor = self.db.cursor(DictCursor)
def __init__(self, tableName): self.db = getdb() self.cursor = self.db.cursor(DictCursor) self.tableName = tableName
# -*- coding:utf-8 from tools.db import getdb import os from selenium import webdriver from selenium.webdriver.chrome.options import Options import json db = getdb() cursor = db.cursor() def get_driver(): driver_path = os.path.dirname(os.path.realpath(__file__)) + "/chromedriver" chrome_options = Options() prefs = {"profile.managed_default_content_settings.images": 2} chrome_options.add_experimental_option("prefs", prefs) chrome_options.add_argument('--headless') return webdriver.Chrome(driver_path, options=chrome_options) driver = get_driver() def get_price(url): if driver == None: get_driver() driver.get(url) try: price = driver.find_element_by_class_name('mainprice').text # print("price", price) except: