#coding=utf-8
import urllib2
#from HandleJs import Py4Js
import threading
import sqlite3
import sys
import time
#from translate import Translator
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
# 为线程定义一个函数
def nomal_data_proc(threadName, conn, min, max):
#counter = 0
#conn.isolation_level = None
#conn.row_factory = sqlite3.Row
cur = conn.cursor()
sql = 'select id, oid, name, summary, affected, solution, insight, vuldetect, impact, synopsis, description, exploitability_ease, risk_factor, metasploit_name, d2_elliot_name from nvts_en where cn_ok = \'0\' and id >' + str(min) + ' and id <= ' + str(max)
print(threadName + ' sql:' + sql)
cur.execute(sql)
results = cur.fetchall()
#data_process(results, cur)
if __name__ == "__main__":
# 3.init db
db_path = 'tasks.db'
conn = sqlite3.connect(db_path, check_same_thread = False)
THTREA_LEN = 10000
# 创建两个线程
count_num = 0
while True:
try:
count_num = count_num + 1
threadName = 'Thread-' + str(count_num)
min = 300 * (count_num -1)
max = 300 * count_num
if min > count_nvts_number:
break
if max >= count_nvts_number:
max = count_nvts_number
# init thread
data_proc = threading.Thread(target = nomal_data_proc, args = (threadName, conn, min, max))
#start thread
data_proc.start()
if max >= count_nvts_number:
break
except:
print("Error: unable to start thread")