| """ | |
| 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) |