from pathlib import Path
import json
import sqlite3
def get_data(file, path):
file_path = Path(file)
if file_path.is_file():
if file_path.suffix.lower() == "json":
with open(file_path, 'r', encoding='utf-8') as f:
json.load(f)
elif file_path.suffix.lower() == "db":
connection = sqlite3.connect(file_path)
connection.row_factory = sqlite3.Row
cursor = connection.cursor()
cursor.execute(f"SELECT * FROM {path}")
rows = cursor.fetchall()
infos = [dict(row) for row in rows]
connection.close()
def set_data(file, path, values):
file_path = Path(file)
if file_path.is_file():
if file_path.suffix.lower() == "json":
with open(file_path, 'r', encoding='utf-8') as f:
json.load(f)
elif file_path.suffix.lower() == "db":
connection = sqlite3.connect(file_path)
connection.row_factory = sqlite3.Row
cursor = connection.cursor()
cursor.execute(f"INSERT INTO {path} ({values.keys()}) VALUES (?, ?)", (name, age)
connection.commit()
connection.close()
To embed this project on your website, copy the following code and paste it into your website's HTML: