Skip to content

Instantly share code, notes, and snippets.

@dyladan
Last active August 29, 2015 14:06
Show Gist options
  • Save dyladan/4a85d63a0d690a52871a to your computer and use it in GitHub Desktop.
Save dyladan/4a85d63a0d690a52871a to your computer and use it in GitHub Desktop.
import csv, sqlite3
con = sqlite3.connect("logstats.sqlite")
cur = con.cursor()
cur.execute("""\
CREATE TABLE messages (
time DATETIME NOT NULL,
server VARCHAR NOT NULL,
chan VARCHAR NOT NULL,
nick VARCHAR NOT NULL,
user VARCHAR,
action VARCHAR,
msg VARCHAR,
uts REAL,
PRIMARY KEY (time, server, chan, nick)
);
"""
)
con.commit()
with open('log.csv','r') as fin:
# csv.DictReader uses first line in file for column headings by default
dr = csv.DictReader(fin) # comma is default delimiter
for i in dr:
row = (i['time'], i['server'], i['chan'], i['nick'], i['user'], i['action'], i['msg'], i['uts'])
cur.execute("INSERT INTO messages (time, server, chan, nick, user, action, msg, uts) VALUES (?, ?, ?, ?, ?, ?, ?, ?);", row)
con.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment