ss14_chemistry_site/db.py

21 lines
470 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')
2024-01-29 17:53:38 +00:00
def read_db(file = 'db.json'):
with open(file, "r", encoding="utf-8") as openfile:
2024-01-24 09:39:30 +00:00
db = json.load(openfile)
return db
2024-01-29 17:53:38 +00:00
def write_db(db, file = 'db.json'):
js = json.dumps(db, indent=2, ensure_ascii=False)
2024-01-29 17:53:38 +00:00
with open(file, "w", encoding="utf-8") as outfile:
outfile.write(js)