Created
March 9, 2016 19:26
-
-
Save vessenes/1485b5e88e00c898199e to your computer and use it in GitHub Desktop.
import of fake data for hn user Y0s
This file contains 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 glob | |
import sqlite3 | |
import shlex | |
import sys | |
import io | |
conn = sqlite3.connect('transaction.db') | |
c = conn.cursor() | |
all = glob.glob("transactions/*") | |
counter = 0 | |
for name in all: | |
counter += 1 | |
f = open(name) | |
lines = [] | |
for line in f.readlines(): | |
cols = shlex.split(line.strip()) | |
user_id = cols[0] | |
date = cols[2] | |
store = cols[1] | |
items = cols[3].split(',') | |
for item in items: | |
lines.append([user_id, store, date, item]) | |
c.executemany("insert into txs values(?,?,?,?)", lines) | |
if counter % 100 == 0: | |
conn.commit() | |
print( "Parsed Customer", name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment