|
|
|
@ -18,7 +18,7 @@ def register(u_name, u_pwd):
|
|
|
|
|
# 获取数据库操作cursor(游标)
|
|
|
|
|
cur = conn.cursor()
|
|
|
|
|
# 编写查询的sql语句
|
|
|
|
|
select_sql = f'select user_password from userinfotest where user_name = "{u_name}"'
|
|
|
|
|
select_sql = f'select user_password from user_info where user_name = "{u_name}"'
|
|
|
|
|
# 执行sql语句
|
|
|
|
|
cur.execute(select_sql)
|
|
|
|
|
# 获取执行结果 fetch_one(),判断结果
|
|
|
|
@ -28,7 +28,7 @@ def register(u_name, u_pwd):
|
|
|
|
|
info = '用户名已存在,注册失败'
|
|
|
|
|
else:
|
|
|
|
|
# 注册-> 插入数据,手动commit
|
|
|
|
|
insert_sql = 'insert into userinfotest (user_name, user_password) values (%s,%s)'
|
|
|
|
|
insert_sql = 'insert into user_info (user_name, user_password, create_time, login_state) values (%s,%s,now(),false)'
|
|
|
|
|
insert_params = [u_name, sha_pwd]
|
|
|
|
|
cur.execute(insert_sql, insert_params)
|
|
|
|
|
conn.commit()
|
|
|
|
@ -48,7 +48,7 @@ def login(u_name, u_pwd):
|
|
|
|
|
try:
|
|
|
|
|
conn = mysql_conn()
|
|
|
|
|
cur = conn.cursor()
|
|
|
|
|
select_sql = f'select user_password from userinfotest where user_name = "{u_name}"'
|
|
|
|
|
select_sql = f'select user_password from user_info where user_name = "{u_name}"'
|
|
|
|
|
cur.execute(select_sql)
|
|
|
|
|
res = cur.fetchone()
|
|
|
|
|
if res is None:
|
|
|
|
@ -59,6 +59,9 @@ def login(u_name, u_pwd):
|
|
|
|
|
m_pwd = res[0]
|
|
|
|
|
if m_pwd == sha_pwd:
|
|
|
|
|
info = '用户' + u_name + '登录成功'
|
|
|
|
|
update_sql = f'update user_info set login_state = true where username = {u_name}'
|
|
|
|
|
cur.execute(update_sql)
|
|
|
|
|
conn.commit()
|
|
|
|
|
else:
|
|
|
|
|
info = '密码错误,登录失败'
|
|
|
|
|
# 关闭连接
|
|
|
|
@ -73,7 +76,7 @@ def cancel(u_name):
|
|
|
|
|
try:
|
|
|
|
|
conn = mysql_conn()
|
|
|
|
|
cur = conn.cursor()
|
|
|
|
|
select_sql = f'delete from userinfotest where username = "{u_name}"'
|
|
|
|
|
select_sql = f'delete from user_info where user_name = "{u_name}"'
|
|
|
|
|
cur.execute(select_sql)
|
|
|
|
|
cur.close()
|
|
|
|
|
conn.close()
|
|
|
|
@ -116,20 +119,10 @@ def drop_table(table_name: str):
|
|
|
|
|
print(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_crawl_result_table(table_name: str):
|
|
|
|
|
def create_table(create_sql: str):
|
|
|
|
|
try:
|
|
|
|
|
conn = mysql_conn()
|
|
|
|
|
cur = conn.cursor()
|
|
|
|
|
create_sql = f'create table if not exists {table_name} (' \
|
|
|
|
|
f'id int primary key not null auto_increment,' \
|
|
|
|
|
f'crawl_id int not null,' \
|
|
|
|
|
f'time timestamp not null,' \
|
|
|
|
|
f'name varchar(100),' \
|
|
|
|
|
f'college varchar(200),' \
|
|
|
|
|
f'major varchar(200),' \
|
|
|
|
|
f'paper varchar(200)' \
|
|
|
|
|
f')'
|
|
|
|
|
|
|
|
|
|
cur.execute(create_sql)
|
|
|
|
|
conn.commit()
|
|
|
|
|
cur.close()
|
|
|
|
@ -138,6 +131,30 @@ def create_crawl_result_table(table_name: str):
|
|
|
|
|
print(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_crawl_result_table(table_name: str):
|
|
|
|
|
create_sql = f'create table if not exists {table_name} (' \
|
|
|
|
|
f'id int primary key not null auto_increment,' \
|
|
|
|
|
f'crawl_id int not null,' \
|
|
|
|
|
f'time timestamp not null,' \
|
|
|
|
|
f'name varchar(100),' \
|
|
|
|
|
f'college varchar(200),' \
|
|
|
|
|
f'major varchar(200),' \
|
|
|
|
|
f'paper varchar(200)' \
|
|
|
|
|
f')'
|
|
|
|
|
create_table(create_sql)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_user_info(table_name: str = 'user_info'):
|
|
|
|
|
create_sql = f'create table if not exists {table_name} (' \
|
|
|
|
|
f'id int primary key not null auto_increment,' \
|
|
|
|
|
f'create_time timestamp not null default now(),' \
|
|
|
|
|
f'user_name varchar(100),' \
|
|
|
|
|
f'user_password varchar(200),' \
|
|
|
|
|
f'login_state boolean default false' \
|
|
|
|
|
f')'
|
|
|
|
|
create_table(create_sql)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def write_result2database(res: list, table_name: str, last_crawl_id: int):
|
|
|
|
|
try:
|
|
|
|
|
conn = mysql_conn()
|
|
|
|
|