File size: 695 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
27
28
29
30
31
"""

Users database operations.

"""

import os
import json
from config import USERS_DB_FILE


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


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


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


def get_user(username):
    users = load_users_db()
    return users.get(username, None)