32 lines
966 B
Python
Executable file
32 lines
966 B
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import dbtools
|
|
|
|
import sqlite3, csv, sys
|
|
|
|
def makeDB(dbo=dbtools.dbHelper(), infile='tweets.csv'):
|
|
"""
|
|
Initializes the database.
|
|
|
|
:param dbo: Database object for the database to be initialized.
|
|
:param infile: Path of the CSV file to initalize the database with.
|
|
:return: Returns nothing.
|
|
"""
|
|
try:
|
|
infile = open(infile)
|
|
except IOError:
|
|
raise IOError("Unable to read %s." % infile)
|
|
|
|
infile = list(csv.reader(infile))
|
|
|
|
for row in infile[1:]:
|
|
try:
|
|
dbo.executeQuery("INSERT INTO tweets VALUES(" + row[0].replace("'","''") + ",'" + row[1].replace("'","''") + "','" + row[2].replace("'","''") + "','" + row[3].replace("'","''") + "','" + row[4].replace("'","''") + "','" + row[5].replace("'","''") + "','" + row[6].replace("'","''") + "','" + row[7].replace("'","''") + "','" + row[8].replace("'","''") + "','" + row[9].replace("'","''") + "');")
|
|
except:
|
|
pass
|
|
|
|
dbo.commit()
|
|
|
|
if __name__ == "__main__":
|
|
makeDB()
|
|
|