vocab_getty_edu.py 文件源码

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

项目:StrepHit 作者: Wikidata 项目源码 文件源码
def load_into_db(self, table):
        def callback(response):
            """ Loads the CSV data contained into the response body and puts it into the appropriate table
            """
            data = itertools.ifilter(lambda x: len(x) == 2,
                                     (row.split(',', 1) for row in response.body_as_unicode().split('\r\n')[1:]))

            cur = self.db_connection.cursor()
            try:
                cur.executemany('INSERT INTO %s(pk, data) VALUES (?, ?)' % table, data)
            except sqlite3.Error:
                self.db_connection.rollback()
                raise
            else:
                self.db_connection.commit()
            finally:
                cur.close()

            for each in self.finalize_data(table):
                yield each
        return callback
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号