-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata.py
More file actions
27 lines (19 loc) · 852 Bytes
/
data.py
File metadata and controls
27 lines (19 loc) · 852 Bytes
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
import json
import os
from pathlib import Path
def load_data():
"""Загружает данные из JSON-файлов."""
# Если скрипт запущен не из tests
if os.path.basename(os.getcwd()) != 'tests':
languages_path = Path(__file__).parent / 'data' / 'languages.json'
menu_path = Path(__file__).parent / 'data' / 'menu.json'
# Если скрипт запущен из tests
else:
languages_path = Path(__file__).parent.parent / 'data' / 'languages.json'
menu_path = Path(__file__).parent.parent / 'data' / 'menu.json'
with open(languages_path, 'r', encoding='utf-8') as f:
LANGUAGES = json.load(f)
with open(menu_path, 'r', encoding='utf-8') as f:
CATEGORIES = json.load(f)
return LANGUAGES, CATEGORIES
LANGUAGES, CATEGORIES = load_data()