def saveData(self, category):
import pymysql.cursors
import pymysql
# Connect to the database
connection = pymysql.connect(host='localhost',
user='root',
password='',
db='hht',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
try:
# ????
with connection.cursor() as cursor:
# Read a single record
sql = "SELECT `id`, `typename`, `py` FROM `type` WHERE `py` = %s"
cursor.execute(sql, category)
typeArr = cursor.fetchone()
# ??????????
with connection.cursor() as cursor:
for resOne in self._res:
sql = "INSERT INTO `res` (`type_id`, `name`, `link`) VALUES (%s, %s, %s)"
cursor.execute(sql, (typeArr['id'], resOne['name'], resOne['res']))
connection.commit()
print 'Insert ' + str(len(self._res)) + ' datas with category ' + typeArr['typename']
del typeArr
finally:
connection.close()
return
# ????
评论列表
文章目录