import pymysql
import re
# import wenjianduqu
def getResult(x,y):
sql=cursor.execute("select regular from regular where regular_id=%d"%x)
regular=cursor.fetchmany(sql)#获取查询结果
Regular=eval(regular[0][0])
regular_result=re.findall(Regular,f)
sql=cursor.execute('insert into regular_result (regular_result,regular_id,file_id) values("%s","%d","%d")'%(regular_result,x,y))
return sql
conn = pymysql.connect(
host='localhost',
port=3306,
user='root',
passwd='123456',
db='zch',
charset='utf8',
)
cursor = conn.cursor()
sql1=cursor.execute("select file_id from file")
info=cursor.fetchmany(sql1)#获取查询结果
#遍历id获得id对应的文件地址,取出并在本机搜索读取
for i in info:
sql = cursor.execute('select file_category_id,file_name from file where file_id=%d'%i)
info = cursor.fetchmany(sql)
address = cursor.execute('select file_address from file_category where file_category_id=%d'%info[0][0])
file_address=cursor.fetchmany(address)
if file_address[0][0] is None :
print("当前文件已经全部遍历完")
break
else:
file=file_address[0][0] +"\"+ info[0][1]
f = open(file, "r",encoding = 'utf-8')
f=f.read()
f = open(file, "r",encoding = 'utf-8')
f=f.read()
if info[0][0] == 1:
regular_id = (1,2,3,4)
for j in regular_id:
getResult(j,i[0])
else:
print('工作结束')
cursor.close()
conn.commit()#数据提交
conn.close()