Spaces:
Runtime error
Runtime error
Create helpers.py
Browse files- utils/helpers.py +24 -0
utils/helpers.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import os
|
3 |
+
import random
|
4 |
+
|
5 |
+
DATA_DIR = "data"
|
6 |
+
|
7 |
+
def load_content():
|
8 |
+
try:
|
9 |
+
with open(os.path.join(DATA_DIR, "afrikaans_content.json"), "r") as f:
|
10 |
+
return json.load(f)
|
11 |
+
except FileNotFoundError:
|
12 |
+
return {}
|
13 |
+
|
14 |
+
def check_spelling(user_answer, correct_word):
|
15 |
+
return user_answer.lower().strip() == correct_word.lower()
|
16 |
+
|
17 |
+
def check_translation(user_answer, correct_translation):
|
18 |
+
return user_answer.lower().strip() == correct_translation.lower()
|
19 |
+
|
20 |
+
def get_random_exercise(category, level, content):
|
21 |
+
if category in content and level in content[category]:
|
22 |
+
exercises = content[category][level]
|
23 |
+
return random.choice(exercises) if exercises else None
|
24 |
+
return None
|