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

Commit

Permalink
FIX: Question catalogue display names without .txt extension
Browse files Browse the repository at this point in the history
  • Loading branch information
claussmann committed Feb 20, 2024
1 parent 181cb1b commit e27d119
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pyteamquiz/__init__.py
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()

0 comments on commit e27d119

Please sign in to comment.