I have 20 json objects that I clean (by removing a few key/value pairs) and send to an sqlite db like so:
import sqlite3
import json
DAILY_FILE = "test.json"
DB = "data.db"
conn = sqlite3.connect(DB)
c = conn.cursor()
c.execute('''create table daily
(time text,
uid text,
bid text,
b text,
total text,
type text)''')
query = "insert into daily values (?,?,?,?,?,?)"
columns = ['time', 'uid', 'bid', 'b', 'total', 'type']
with open(DAILY_FILE) as f:
for line in f:
x = json.loads(line)
del x['domain']
del x['user']
del x['query']
del x['hours']
keys = tuple(x[c] for c in columns)
c.execute(query, keys)
c.close()
I'm not getting any errors, but I'm also not seeing any data in the database. Any thoughts on why this might be happening?
Aucun commentaire:
Enregistrer un commentaire