db 재접속 수정

git-svn-id: svn://192.168.0.12/source@248 8346c931-da38-4b9b-9d4c-e48b93cbd075
This commit is contained in:
admin
2016-01-29 09:12:42 +00:00
parent 44c1dbc2c3
commit aba95f750e

View File

@@ -230,17 +230,36 @@ class SendtoDB:
if not body: if not body:
return return
self.conn_check() self.conn_check()
with self.conn.cursor() as cursor: query = self.make_insert_query(body)
query = self.make_insert_query(body) try:
try: with self.conn.cursor() as cursor:
cursor.execute(query) cursor.execute(query)
self.conn.commit() self.conn.commit()
except Exception as e: except self.pymysql.err.OperationalError as e:
pass print(e)
# print(e) if e.args[0] == 2013 or e.args[0] == 2006: # Lost connection to server
# sys.stdout.flush() print("connection lost. try to reconnection")
# print(query) self.conn = self.pymysql.connect(host='bigbird.iptime.org',
# sys.stdout.flush() 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): def send_reply(self, reply):
if not reply: if not reply:
@@ -261,16 +280,36 @@ class SendtoDB:
def delete_url(self, url): def delete_url(self, url):
query = "delete from data_" + str(self.db_num) + " where article_url = " + self.conn.escape(str(url)) query = "delete from data_" + str(self.db_num) + " where article_url = " + self.conn.escape(str(url))
self.conn_check() self.conn_check()
with self.conn.cursor() as cursor: try:
try: with self.conn.cursor() as cursor:
cursor.execute(query) cursor.execute(query)
self.conn.commit() self.conn.commit()
except Exception as e: except self.pymysql.err.OperationalError as e:
print(e) print(e)
sys.stdout.flush() if e.args[0] == 2013 or e.args[0] == 2006: # Lost connection to server
print(query) print("connection lost. try to reconnection")
sys.stdout.flush() 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: class CrawlInit:
pymysql = __import__('pymysql.cursors') pymysql = __import__('pymysql.cursors')