def dbwrite(p,x1,x2):
	try :
		connection = MySQLdb.connect('localhost', 'root', 'kgggdkp2692', 'mining')
	except Exception as e :
		connection =None
		print "Unable to connect   :" + str(e)

	x = connection.cursor()
	try:
		q= "INSERT INTO `data_new` (`path`,`topic`,`data`) VALUES ('"+str(p)+"','"+json.dumps(x1).replace('\'', '\\\'')+"','"+json.dumps(x2).replace('\'', '\\\'')+"')"
		x.execute(q)
		connection.commit()
	except Exception as e :
		print e
		connection.rollback()
		connection.close()
import json, MySQLdb
from lib.dpattern import DP
from lib.mysql import connection

cursor = connection.cursor()
cursor2 = connection.cursor()
query = "SELECT `sno`,`data` FROM `data_new` WHERE 1 and `dp` is Null "
cursor.execute(query)

results = cursor.fetchall()
dp = DP(0.2)
for row in results :
	print row[0]
	dps = dp.d_patterns(json.loads(row[1]))
	query = "update `data_new` set dp = '%s' where `sno` = %s" %(json.dumps(dps).replace('\'', '\\\''), str(row[0]))
	try :
		cursor2.execute(query)
		connection.commit()
	except Exception as e:
		print e

示例#3
0
	    for payload in msg.get_payload():
	    	for p in payload.get_payload():
			try:
	        		body += p.get_payload()
			except:
				body += str(p)
	else:
	    body = msg.get_payload()
	try:
		for url in re.findall(r'[a-zA-Z]+://[^\s<>"]+|www\.[^\s<>"]+', body):
			meta_data.append(get_domain(url))
		print re.replace(r'<[/]?[^>]+>', '', body)
	except:
		pass
	for typ in EMAIL_CHECK_TYPES:
		if msg[typ]:
			mail = get_email(msg[typ])
			if mail not in meta_data:
				meta_data.append(mail)

	recv_info = str(msg.get_all('received'))
	meta_data += get_ips(recv_info)
	print meta_data

	for char in UNWANTED_CHARS:
		body.replace(char, '')
	body = DataClean(body).GetData()
	query = "INSERT INTO `data_mail` (`path`,`data`, `meta-data`) VALUES ('%s','%s','%s')" %(file, json.dumps(str(body)).replace('\'', '\\\''), json.dumps(str(meta_data)).replace('\'', '\\\''))
	cursor.execute(query)
	connection.commit()