diff --git a/tools/questions2json.py b/tools/questions2json.py index b06b342..98facfc 100755 --- a/tools/questions2json.py +++ b/tools/questions2json.py @@ -13,7 +13,6 @@ readeable format assuming yaml is more human readable TODO: * Add own constructor to Question() / nice to have * Deal with media files - * Fix to output only questions per round as json """ __author__ = "Frank Becker " @@ -160,6 +159,10 @@ def init_parser(): options = parser.parse_args()[0] return options +def questions_per_round(questions, game_round=None): + """docstring for questions_per_round""" + return [q for q in questions if q.game_round == game_round] + def main(): """docstring for main""" @@ -181,7 +184,12 @@ def main(): questions.append(q) if options.debug: print Question.registered_questions - print json.dumps([q.as_dict for q in questions], indent=2) + + game_rounds = sorted(Question.registered_questions.keys()) + for r in game_rounds: + print json.dumps([q.as_dict for q in questions_per_round( + questions, game_round=r)], indent=2) + if __name__ == '__main__': main() diff --git a/tools/test_questions.yaml b/tools/test_questions.yaml new file mode 100644 index 0000000..37bd80d --- /dev/null +++ b/tools/test_questions.yaml @@ -0,0 +1,55 @@ +#--- !Question +#question: What is the question? +#answers: +# - Answer 1 +# - Answer 2 +# - Answer 3 +# - Answer 4 +#tier: 1 +#game_round: 1 +#media: +# - aaa +# - bbb +# - ccc + +!!python/object:__main__.Question +question: What is the question? +answers: + - true: Answer 1 + - false: Answer 2 + - false: Answer 3 + - false: Answer 4 +tier: 1 +game_round: 1 +media: + - pix/question1.png + - pix/question1_big.png + - videos/question1.webm + +--- !Question +question: What are users in Facebook called? +answers: + - false: Hostage + - false: Victims + - true: Target + - false: Product +tier: 2 +game_round: 1 +media: + - pix/facebook.jpg + - pix/facebook-jail.png + - videos/faschistbook.webm + +--- !Question +question: What are users in Facebook called? +answers: + - false: Hostage + - false: Victims + - true: Target + - false: Product +tier: 2 +game_round: 2 +media: + - pix/facebook.jpg + - pix/facebook-jail.png + - videos/faschistbook.webm