20 lines
590 B
Python
20 lines
590 B
Python
import json
|
|
import sqlite3
|
|
|
|
with open('cnes_estabelecimentos.json', 'r', encoding='utf-8') as f:
|
|
data = json.load(f)
|
|
|
|
conn = sqlite3.connect('db.sqlite3')
|
|
cursor = conn.cursor()
|
|
|
|
if data:
|
|
columns = ', '.join([f"{key} TEXT" for key in data[0].keys()])
|
|
cursor.execute(f"CREATE TABLE IF NOT EXISTS cnes_estabelecimentos ({columns})")
|
|
|
|
placeholders = ', '.join(['?' for _ in data[0].keys()])
|
|
for record in data:
|
|
cursor.execute(f"INSERT INTO cnes_estabelecimentos VALUES ({placeholders})",
|
|
list(record.values()))
|
|
|
|
conn.commit()
|
|
conn.close() |