mirror of
https://github.com/5ee/SocialEngineerDBuilder.git
synced 2026-10-17 04:31:08 +08:00
b
This commit is contained in:
@@ -6,7 +6,7 @@ from __future__ import print_function
|
||||
import sys
|
||||
import sqlalchemy
|
||||
from User import user_model
|
||||
from Common import get_DB_engine,init_User_table,get_DB_session,preConstuct
|
||||
from Common import get_DB_engine,init_User_table,get_DB_session,preConstruct
|
||||
|
||||
|
||||
def gen_parse_class(f_name):
|
||||
|
||||
@@ -43,7 +43,7 @@ def build_sql_by_tmpl(source_file,template,single_file=False,model=user_model):
|
||||
sep,columns = preConstruct(f.readline())
|
||||
|
||||
if sep == 'SPACE':
|
||||
sep = '\s'
|
||||
sep = ' '
|
||||
columns = [c.strip() for c in columns]
|
||||
if not check_col_name(columns): return False
|
||||
|
||||
@@ -51,13 +51,13 @@ def build_sql_by_tmpl(source_file,template,single_file=False,model=user_model):
|
||||
table_name = model.__tablename__
|
||||
|
||||
sql_query = """LOAD DATA LOCAL INFILE '{0}'
|
||||
INTO TABLE {1}
|
||||
FIELDS TERMINATED BY '{2}'
|
||||
ENCLOSED BY '\\''
|
||||
LINES TERMINATED BY '\\r\\n'
|
||||
{3}
|
||||
({4});
|
||||
""".format(
|
||||
INTO TABLE {1}
|
||||
FIELDS TERMINATED BY '{2}'
|
||||
OPTIONALLY ENCLOSED BY '\\''
|
||||
LINES TERMINATED BY '\\r\\n'
|
||||
{3}
|
||||
({4});
|
||||
""".format(
|
||||
source_file,
|
||||
table_name,
|
||||
sep,
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
import traceback
|
||||
import sqlalchemy
|
||||
from User import user_model
|
||||
from Common import get_DB_engine,init_User_table,get_DB_session,preConstruct,check_col_name
|
||||
@@ -38,7 +39,9 @@ def gen_parse_class(f_name):
|
||||
else:
|
||||
kargs[columns[ele_i]] = row_elements[ele_i]
|
||||
except Exception,e:
|
||||
sys.stdout.write(e)
|
||||
sys.stdout.write('\n {0} \r'.format(e))
|
||||
#print(ele_i,columns,row_elements)
|
||||
#print(e)
|
||||
# do the init
|
||||
super(spec_user_model,self).__init__(**kargs)
|
||||
|
||||
@@ -66,16 +69,18 @@ def gen_parse_class(f_name):
|
||||
# do one job
|
||||
def save_to_db(fname,user_class,single_file=False,lines_num=1000):
|
||||
"""
|
||||
save
|
||||
"""
|
||||
sess = get_DB_session()
|
||||
#sess.autocommit = True
|
||||
with open(fname) as f:
|
||||
if single_file==True:
|
||||
f.readline()
|
||||
print(f.readline())
|
||||
line_n = 0
|
||||
while True:
|
||||
for line in f:
|
||||
try:
|
||||
#print(line,type(line))
|
||||
user = user_class(line)
|
||||
sess.add(user)
|
||||
line_n += 1
|
||||
|
||||
Reference in New Issue
Block a user