hht.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:hht 作者: zlizhe 项目源码 文件源码
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

    # ????
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号