twitools/csvdb.py
Klaus-Uwe Mitterer aad1531392 Futher preparation for MySQL, which is not working yet though...
Make filler handle direct messages
Add table and functions for direct messages
2016-06-30 12:33:09 +02:00

25 lines
767 B
Python
Executable file

#!/usr/bin/env python3
import dbtools
import sqlite3, csv, sys
def makeDB(dbo=dbtools.dbHelper(), infile='tweets.csv'):
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()