This repository has been archived by the owner on Jan 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: Question catalogue display names without .txt extension
- Loading branch information
1 parent
181cb1b
commit e27d119
Showing
1 changed file
with
15 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
import os | ||
from .question import QuestionCatalogueFile | ||
|
||
|
||
|
||
# Settings (possibly from env variables) | ||
settings = { | ||
"QUESTION_CATALOGUE_DIR": os.environ.get("QUESTION_CATALOGUE_DIR", "../questions/"), | ||
} | ||
|
||
|
||
|
||
# Read Question Catalogues | ||
def _is_valid_filename(fn): | ||
if not fn.endswith(".txt"): | ||
return False | ||
fn = fn[:len(fn) - 4] | ||
return len(fn) > 0 and not fn.isspace() | ||
|
||
games = dict() | ||
question_catalogue_dir = settings["QUESTION_CATALOGUE_DIR"] | ||
if os.path.isdir(question_catalogue_dir): | ||
catalogues = { | ||
filename: QuestionCatalogueFile(filename=os.path.join(question_catalogue_dir, filename)) | ||
for filename in os.listdir(question_catalogue_dir) | ||
if filename.endswith(".txt") | ||
fn[:len(fn) - 4]: QuestionCatalogueFile(filename=os.path.join(question_catalogue_dir, fn)) | ||
for fn in os.listdir(question_catalogue_dir) | ||
if _is_valid_filename(fn) | ||
} | ||
else: | ||
catalogues = dict() |