-
-
Save synsa/9e01c1a1c1b898e145f90706b666dbf0 to your computer and use it in GitHub Desktop.
create sqlite database file from json file
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
# -*- coding:utf-8 -*- | |
import json | |
import sqlite3 | |
JSON_FILE = "some.json" | |
DB_FILE = "some.db" | |
traffic = json.load(open(JSON_FILE)) | |
conn = sqlite3.connect(DB_FILE) | |
foo = traffic[0]["foo"] | |
bar = traffic[0]["bar"] | |
data = [foo, bar] | |
c = conn.cursor() | |
c.execute('create table table_name (foo, bar)') | |
c.execute('insert into table_name values (?,?)', data) | |
conn.commit() | |
c.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment