mirror of
https://github.com/appinfosapienza/so-un-bot.git
synced 2025-03-13 13:05:22 +01:00
/bin/python /home/marco/so-un-bot/scripts/validate_questions.py
This commit is contained in:
parent
6988ff0549
commit
5b49781fa6
1 changed files with 10 additions and 7 deletions
|
@ -12,22 +12,25 @@ for filename in os.listdir("data/questions"):
|
|||
data = json.loads(text)
|
||||
|
||||
for q in data:
|
||||
if type(q["quest"]) is not str or type(q["image"]) is not str or type(q["answers"]) is not list or type(q["correct"]) is not int:
|
||||
raise Exception(str(data.index(q)) + ": Some parameters are null, missing or their type is wrong.")
|
||||
|
||||
if q["quest"] == "" and q["image"] == "":
|
||||
raise Exception(str(data.index(q)) + ") Question's text and image cannot both be empty.")
|
||||
if q["quest"] is None or q["image"] is None or q["answers"] is None or q["correct"] is None:
|
||||
raise Exception(str(data.index(q)) + ") Some parameters are null or missing.")
|
||||
|
||||
if len(q["answers"]) == 0:
|
||||
raise Exception(str(data.index(q)) + ") Question has no answers.")
|
||||
raise Exception(str(data.index(q)) + ": Question has no answers.")
|
||||
|
||||
for a in q["answers"]:
|
||||
if a["text"] == "" and a["image"] == "":
|
||||
raise Exception(str(data.index(q)) + ") Answer's text and image cannot both be empty.")
|
||||
if a["text"] is None or a["image"] is None:
|
||||
raise Exception(str(data.index(q)) + ") Some answer's parameters are null or missing.")
|
||||
raise Exception(str(data.index(q)) + ": Answer's text and image cannot both be empty.")
|
||||
if type(a["text"]) is not str or type(a["image"]) is not str:
|
||||
raise Exception(str(data.index(q)) + ": Some answer's parameters are null, missing or their type is wrong.")
|
||||
|
||||
except Exception as e:
|
||||
logging.error(getattr(e, 'message', repr(e)))
|
||||
logging.fatal(filename + " is invalid. Aborting.")
|
||||
exit(1)
|
||||
|
||||
logging.info("Parsing successful!")
|
||||
exit(0)
|
Loading…
Reference in a new issue