db 재접속 수정
git-svn-id: svn://192.168.0.12/source@248 8346c931-da38-4b9b-9d4c-e48b93cbd075
This commit is contained in:
@@ -230,17 +230,36 @@ class SendtoDB:
|
||||
if not body:
|
||||
return
|
||||
self.conn_check()
|
||||
with self.conn.cursor() as cursor:
|
||||
query = self.make_insert_query(body)
|
||||
try:
|
||||
query = self.make_insert_query(body)
|
||||
try:
|
||||
with self.conn.cursor() as cursor:
|
||||
cursor.execute(query)
|
||||
self.conn.commit()
|
||||
except Exception as e:
|
||||
pass
|
||||
# print(e)
|
||||
# sys.stdout.flush()
|
||||
# print(query)
|
||||
# sys.stdout.flush()
|
||||
except self.pymysql.err.OperationalError as e:
|
||||
print(e)
|
||||
if e.args[0] == 2013 or e.args[0] == 2006: # Lost connection to server
|
||||
print("connection lost. try to reconnection")
|
||||
self.conn = self.pymysql.connect(host='bigbird.iptime.org',
|
||||
user='admin', passwd='admin123',
|
||||
db='concepters', charset='utf8',
|
||||
cursorclass=self.pymysql.cursors.DictCursor)
|
||||
with self.conn.cursor() as cursor:
|
||||
cursor.execute(query)
|
||||
self.conn.commit()
|
||||
except self.pymysql.err.MySQLError as e:
|
||||
print(e)
|
||||
if e.args[0] == 2013 or e.args[0] == 2006: # Lost connection to server
|
||||
print("connection lost. try to reconnection")
|
||||
self.conn = self.pymysql.connect(host='bigbird.iptime.org',
|
||||
user='admin', passwd='admin123',
|
||||
db='concepters', charset='utf8',
|
||||
cursorclass=self.pymysql.cursors.DictCursor)
|
||||
with self.conn.cursor() as cursor:
|
||||
cursor.execute(query)
|
||||
self.conn.commit()
|
||||
except Exception as e:
|
||||
print(e, flush=True)
|
||||
print(query, flush=True)
|
||||
|
||||
def send_reply(self, reply):
|
||||
if not reply:
|
||||
@@ -261,16 +280,36 @@ class SendtoDB:
|
||||
def delete_url(self, url):
|
||||
query = "delete from data_" + str(self.db_num) + " where article_url = " + self.conn.escape(str(url))
|
||||
self.conn_check()
|
||||
with self.conn.cursor() as cursor:
|
||||
try:
|
||||
try:
|
||||
with self.conn.cursor() as cursor:
|
||||
cursor.execute(query)
|
||||
self.conn.commit()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
sys.stdout.flush()
|
||||
print(query)
|
||||
sys.stdout.flush()
|
||||
|
||||
except self.pymysql.err.OperationalError as e:
|
||||
print(e)
|
||||
if e.args[0] == 2013 or e.args[0] == 2006: # Lost connection to server
|
||||
print("connection lost. try to reconnection")
|
||||
self.conn = self.pymysql.connect(host='bigbird.iptime.org',
|
||||
user='admin', passwd='admin123',
|
||||
db='concepters', charset='utf8',
|
||||
cursorclass=self.pymysql.cursors.DictCursor)
|
||||
with self.conn.cursor() as cursor:
|
||||
cursor.execute(query)
|
||||
self.conn.commit()
|
||||
except self.pymysql.err.MySQLError as e:
|
||||
print(e)
|
||||
if e.args[0] == 2013 or e.args[0] == 2006: # Lost connection to server
|
||||
print("connection lost. try to reconnection")
|
||||
self.conn = self.pymysql.connect(host='bigbird.iptime.org',
|
||||
user='admin', passwd='admin123',
|
||||
db='concepters', charset='utf8',
|
||||
cursorclass=self.pymysql.cursors.DictCursor)
|
||||
with self.conn.cursor() as cursor:
|
||||
cursor.execute(query)
|
||||
self.conn.commit()
|
||||
except Exception as e:
|
||||
print(e, flush=True)
|
||||
print(query, flush=True)
|
||||
|
||||
|
||||
class CrawlInit:
|
||||
pymysql = __import__('pymysql.cursors')
|
||||
|
||||
Reference in New Issue
Block a user