File size: 599 Bytes
b83571a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""

Cards database operations.

"""

import os
import json
from config import CARDS_DB_FILE


def init_cards_db():
    if not os.path.exists(CARDS_DB_FILE):
        with open(CARDS_DB_FILE, 'w', encoding='utf-8') as f:
            json.dump({}, f, ensure_ascii=False)


def load_cards_db():
    try:
        with open(CARDS_DB_FILE, 'r', encoding='utf-8') as f:
            return json.load(f)
    except Exception:
        return {}


def save_cards_db(data):
    with open(CARDS_DB_FILE, 'w', encoding='utf-8') as f:
        json.dump(data, f, indent=4, ensure_ascii=False)