import _mysql
class MySql:
def __init__(self):
self.db = _mysql.connect(host="localhost", user="root", passwd="", db="cloner")
def query(self, sql):
self.db.query(sql)
return self.db.store_result()
def getItem(self):
getProjectQuery = self.query("SELECT * FROM projects WHERE status=0 LIMIT 1")
row = getProjectQuery.fetch_row(how=1)
return row
def setItemProcess(self, id):
projectStatusProcess = self.query("UPDATE projects SET status=1 WHERE id=" + id)
return projectStatusProcess
def setItemDone(self, path, id):
projectStatusDone = self.query("UPDATE projects SET status=2, project_path='" + path + "' WHERE id=" + id)
return projectStatusDone
if __name__ == "__main__":
mysql = database.MySql()
while True:
row = mysql.getItem()
if len(row) > 0:
row = row[0]
projectStatusUpdateQuery = mysql.setItemProcess(row['id'])
project_url = row["project_url"].decode('utf8')
project_name = row["project_name"].decode('utf8')
user_id = row["user_id"]
project_id = row["id"]
crawl = crawler.Crawler(
url=project_url,
project_name=project_name,
user_id=user_id,
project_id=project_id)
crawl.start()
else:
continue
_mysql_exceptions.OperationalError: (2013, 'Lost connection to MySQL server during query')
[
{id:1, level:0},
{id:2, level:1},
{id:3, level:0},
{id:4, level:1},
]
{id:1, level:0, node: [
{id:2, level:1},
{id:4, level:1}
]},
{id:3, level:3}