Fix csvdb dependencies
This commit is contained in:
parent
c6c994926d
commit
12df347fc5
1 changed files with 6 additions and 9 deletions
15
csvdb.py
15
csvdb.py
|
@ -1,10 +1,10 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import tools
|
import dbtools
|
||||||
|
|
||||||
import sqlite3, csv, sys
|
import sqlite3, csv, sys
|
||||||
|
|
||||||
def makeDB(path=tools.dbpath(), infile='tweets.csv'):
|
def makeDB(dbo=dbtools.dbObject(), infile='tweets.csv'):
|
||||||
try:
|
try:
|
||||||
infile = open(infile)
|
infile = open(infile)
|
||||||
except IOError:
|
except IOError:
|
||||||
|
@ -12,18 +12,15 @@ def makeDB(path=tools.dbpath(), infile='tweets.csv'):
|
||||||
|
|
||||||
input = list(csv.reader(infile))
|
input = list(csv.reader(infile))
|
||||||
|
|
||||||
conn = sqlite3.connect(path)
|
|
||||||
cur = conn.cursor()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cur.execute("CREATE TABLE tweets(`tweet_id` INTEGER NOT NULL, `in_reply_to_status_id` TEXT, `in_reply_to_user_id` TEXT, `timestamp` TEXT, `source` TEXT, `text` TEXT, `retweeted_status_id` TEXT, `retweeted_status_user_id` TEXT, `retweeted_status_timestamp` TEXT, `expanded_urls` TEXT, PRIMARY KEY(tweet_id));")
|
dbo.executeQuery("CREATE TABLE tweets(`tweet_id` INTEGER NOT NULL, `in_reply_to_status_id` TEXT, `in_reply_to_user_id` TEXT, `timestamp` TEXT, `source` TEXT, `text` TEXT, `retweeted_status_id` TEXT, `retweeted_status_user_id` TEXT, `retweeted_status_timestamp` TEXT, `expanded_urls` TEXT, PRIMARY KEY(tweet_id));")
|
||||||
except sqlite3.OperationalError:
|
except:
|
||||||
raise IOError("%s already exists. Please delete it before trying to create a new one." % path)
|
raise IOError("%s already exists. Please delete it before trying to create a new one." % path)
|
||||||
|
|
||||||
for row in input[1:]:
|
for row in input[1:]:
|
||||||
cur.execute("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("'","''") + "');")
|
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("'","''") + "');")
|
||||||
|
|
||||||
conn.commit()
|
dbo.commit()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) > 2:
|
if len(sys.argv) > 2:
|
||||||
|
|
Loading…
Reference in a new issue