@@ -0,0 +1,2207 @@
+#!/usr/bin/env python%0A%0Aimport sqlite3%0Aimport csv%0Aimport argparse%0A%0Aclass CsvToSqlite(object):%0A    @staticmethod%0A    def createSQLite(csvFile, dbFile, tableName):%0A        with open(csvFile, 'r') as f:%0A            csvReader = csv.DictReader(open(csvFile, 'r'), delimiter=',')%0A%0A            # create sqlite db%0A            conn = sqlite3.connect(dbFile)%0A            c = conn.cursor()%0A%0A            # Create a table creation query%0A            # Get the first row, and base the data types for the columns on this row%0A            row = csvReader.next()%0A%0A            keys = row.keys()%0A            fielddefs = %5B%5D;%0A            for key in keys:%0A                if row%5Bkey%5D.isdigit():%0A                    coltype = 'INTEGER'%0A                elif CsvToSqlite.is_float(row%5Bkey%5D):%0A                    coltype = 'REAL'%0A                else:%0A                    coltype = 'TEXT'%0A                fielddefs.append('%22%25s%22 %25s' %25 (key, coltype))%0A%0A            q = 'CREATE TABLE IF NOT EXISTS %22%25s%22 (%22id%22 INTEGER PRIMARY KEY AUTOINCREMENT, %25s)' %25 (tableName, ','.join(fielddefs))%0A            c.execute(q)%0A            insertQuery = 'INSERT INTO %25s (%25s) VALUES (%25s)' %25 (tableName, ','.join(keys), ','.join(%5B':' + x for x in keys%5D));%0A%0A            c.execute(insertQuery, row)%0A            for row in csvReader:%0A                c.execute(insertQuery, row)%0A%0A            print('%5CtWriting %25s' %25 dbFile)%0A            conn.commit()%0A%0A    @staticmethod%0A    def is_float(var):%0A        try:%0A            float(var)%0A            return True%0A        except ValueError:%0A            return False%0A%0A    @staticmethod%0A    def parseArguments():%0A        parser = argparse.ArgumentParser(description=%22%22%22Convert csv file to an SQLite3 database%22%22%22)%0A        parser.add_argument('--csv',   type=str, dest='csvFile',    required=True, help='Input csv.')%0A        parser.add_argument('--db',    type=str, dest='dbFile',     required=True, help='Output sqlite file.')%0A        parser.add_argument('--table', type=str, dest='tableName',  required=True, help='Name of the database table to create.')%0A        return parser.parse_args()%0A%0Aif __name__ == '__main__':%0A    args = CsvToSqlite.parseArguments()%0A    CsvToSqlite.createSQLite(args.csvFile, args.dbFile, args.tableName)%0A

Create CsvToSqlite.py