ss14_chemistry_site/db.py

21 lines
446 B
Python
Raw Normal View History

2024-01-24 09:39:30 +00:00
import os
import json
if not os.path.exists('db.json'):
db = {}
js = json.dumps(db, indent=2)
with open("db.json", "w") as outfile:
outfile.write(js)
print('Created new db.json')
def read_db():
with open("db.json", "r", encoding="utf-8") as openfile:
2024-01-24 09:39:30 +00:00
db = json.load(openfile)
return db
2024-01-24 09:39:30 +00:00
def write_db(db):
js = json.dumps(db, indent=2, ensure_ascii=False)
with open("db.json", "w", encoding="utf-8") as outfile:
outfile.write(js)