Skip to content

Instantly share code, notes, and snippets.

@vessenes
Created March 9, 2016 19:26
Show Gist options
  • Save vessenes/1485b5e88e00c898199e to your computer and use it in GitHub Desktop.
Save vessenes/1485b5e88e00c898199e to your computer and use it in GitHub Desktop.
import of fake data for hn user Y0s
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