Last active
August 29, 2015 14:06
-
-
Save dyladan/4a85d63a0d690a52871a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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