2024-04-01 16:37:33 +00:00
|
|
|
import os
|
|
|
|
import json
|
2024-05-04 11:20:09 +00:00
|
|
|
from reag__ import reag__
|
2024-04-01 16:37:33 +00:00
|
|
|
|
|
|
|
if not os.path.exists('db.json'):
|
|
|
|
db = {}
|
|
|
|
js = json.dumps(db, indent=2)
|
2024-05-04 11:20:09 +00:00
|
|
|
with open('db.json', 'w') as outfile:
|
2024-04-01 16:37:33 +00:00
|
|
|
outfile.write(js)
|
|
|
|
print('Created new db.json')
|
2024-05-04 11:20:09 +00:00
|
|
|
if not os.path.exists('raw_db.json'):
|
|
|
|
db = {}
|
|
|
|
js = json.dumps(db, indent=2)
|
|
|
|
with open('raw_db.json', 'w') as outfile:
|
|
|
|
outfile.write(js)
|
|
|
|
print('Created new raw_db.json')
|
2024-04-01 16:37:33 +00:00
|
|
|
|
|
|
|
|
2024-05-04 11:20:09 +00:00
|
|
|
def read_db(file):
|
|
|
|
with open(file, 'r', encoding='utf-8') as openfile:
|
2024-04-01 16:37:33 +00:00
|
|
|
db = json.load(openfile)
|
|
|
|
return db
|
|
|
|
|
2024-05-04 11:20:09 +00:00
|
|
|
def write_db(db, file):
|
2024-04-01 16:37:33 +00:00
|
|
|
js = json.dumps(db, indent=2, ensure_ascii=False)
|
2024-05-04 11:20:09 +00:00
|
|
|
with open(file, 'w', encoding='utf-8') as outfile:
|
2024-04-01 16:37:33 +00:00
|
|
|
outfile.write(js)
|
2024-05-04 11:20:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def save(db, file):
|
|
|
|
raw = {}
|
|
|
|
for el in db:
|
|
|
|
class_data = db[el].get_all()
|
|
|
|
raw[el] = class_data
|
|
|
|
write_db(raw, file)
|
|
|
|
|
|
|
|
def load(file):
|
|
|
|
raw = read_db(file)
|
|
|
|
db = {}
|
|
|
|
for el in raw:
|
|
|
|
db[el] = reag__(raw[el][0], raw[el][1], raw[el][2])
|
|
|
|
return db
|