Skip to content
This repository was archived by the owner on Jan 4, 2025. It is now read-only.

Commit e27d119

Browse files
committed
FIX: Question catalogue display names without .txt extension
1 parent 181cb1b commit e27d119

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

pyteamquiz/__init__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
import os
22
from .question import QuestionCatalogueFile
33

4+
5+
6+
# Settings (possibly from env variables)
47
settings = {
58
"QUESTION_CATALOGUE_DIR": os.environ.get("QUESTION_CATALOGUE_DIR", "../questions/"),
69
}
710

11+
12+
13+
# Read Question Catalogues
14+
def _is_valid_filename(fn):
15+
if not fn.endswith(".txt"):
16+
return False
17+
fn = fn[:len(fn) - 4]
18+
return len(fn) > 0 and not fn.isspace()
19+
820
games = dict()
921
question_catalogue_dir = settings["QUESTION_CATALOGUE_DIR"]
1022
if os.path.isdir(question_catalogue_dir):
1123
catalogues = {
12-
filename: QuestionCatalogueFile(filename=os.path.join(question_catalogue_dir, filename))
13-
for filename in os.listdir(question_catalogue_dir)
14-
if filename.endswith(".txt")
24+
fn[:len(fn) - 4]: QuestionCatalogueFile(filename=os.path.join(question_catalogue_dir, fn))
25+
for fn in os.listdir(question_catalogue_dir)
26+
if _is_valid_filename(fn)
1527
}
1628
else:
1729
catalogues = dict()

0 commit comments

Comments
 (0)