arch & placeholders
This commit is contained in:
parent
a3b16ae58a
commit
57543e139a
10 changed files with 233 additions and 2 deletions
22
storage/repository.py
Normal file
22
storage/repository.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import json
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
DATA_FILE = Path("data/warmachron.json")
|
||||
|
||||
def load_data():
|
||||
if not DATA_FILE.exists() or DATA_FILE.stat().st_size == 0:
|
||||
return {"version": 1, "players": {}, "wars": []}
|
||||
|
||||
try:
|
||||
with open(DATA_FILE, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
except json.JSONDecodeError:
|
||||
raise RuntimeError("Data file is corrupted")
|
||||
|
||||
def save_data(data):
|
||||
if DATA_FILE.exists():
|
||||
shutil.copy(DATA_FILE, DATA_FILE.with_suffix(".json.bak"))
|
||||
|
||||
with open(DATA_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f, indent=2)
|
||||
Loading…
Add table
Add a link
Reference in a new issue