2015-04-13 20:58:32 +00:00
#!/usr/bin/env python3
2015-04-12 23:58:32 +00:00
2016-04-07 22:23:04 +00:00
import dbtools
2015-04-13 00:14:34 +00:00
2016-02-08 00:55:12 +00:00
import sqlite3 , csv , sys
2015-04-12 23:58:32 +00:00
2016-06-30 10:33:09 +00:00
def makeDB ( dbo = dbtools . dbHelper ( ) , infile = ' tweets.csv ' ) :
2017-01-27 21:02:53 +00:00
"""
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 .
"""
2015-10-10 22:10:57 +00:00
try :
2016-04-07 19:04:13 +00:00
infile = open ( infile )
2015-10-10 22:10:57 +00:00
except IOError :
2016-04-07 19:04:13 +00:00
raise IOError ( " Unable to read %s . " % infile )
2015-10-10 22:10:57 +00:00
2016-06-30 10:33:09 +00:00
infile = list ( csv . reader ( infile ) )
2015-10-10 22:10:57 +00:00
2016-06-30 10:33:09 +00:00
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
2015-10-10 22:10:57 +00:00
2016-04-07 22:23:04 +00:00
dbo . commit ( )
2015-10-10 22:10:57 +00:00
if __name__ == " __main__ " :
2016-06-30 10:33:09 +00:00
makeDB ( )
2015-04-12 23:58:32 +00:00