diff --git a/tools/questions2json.py b/tools/questions2json.py index 3868bd5..b9f2acc 100755 --- a/tools/questions2json.py +++ b/tools/questions2json.py @@ -9,10 +9,13 @@ some yaml format to json. It's just a helper to write the questions in a more human readeable format assuming yaml is more human readable +Note: + - Media files are looked for relative to the questions file + - Media files are expected relative to the generated json files TODO: * Add own constructor to Question() / nice to have - * Deal with media files + * Use import logging for debug logging """ __author__ = "Frank Becker " @@ -191,6 +194,13 @@ 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 write_json_file(questions): + """docstring for write_json_file""" + game_round = questions[0].game_round + file_name = 'round_{0}.json'.format(game_round) + fh = open(file_name, 'w') + fh.writelines(json.dumps([q.as_dict for q in questions], indent=2)) + def main(): """docstring for main""" @@ -218,8 +228,9 @@ def main(): 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) + write_json_file(questions_per_round(questions, game_round=r)) + if options.debug: + print "Written file for game round: {0}".format(r) if __name__ == '__main__': main() diff --git a/tools/test_data/pix/facebook-jail.png b/tools/test_data/pix/facebook-jail.png new file mode 100644 index 0000000..e69de29 diff --git a/tools/test_data/pix/facebook.jpg b/tools/test_data/pix/facebook.jpg new file mode 100644 index 0000000..d486ca7 Binary files /dev/null and b/tools/test_data/pix/facebook.jpg differ diff --git a/tools/test_data/pix/question1.png b/tools/test_data/pix/question1.png new file mode 100644 index 0000000..26d04d7 Binary files /dev/null and b/tools/test_data/pix/question1.png differ diff --git a/tools/test_data/test_questions.yaml b/tools/test_data/test_questions.yaml index 02e5b22..97a78ea 100644 --- a/tools/test_data/test_questions.yaml +++ b/tools/test_data/test_questions.yaml @@ -23,9 +23,9 @@ game_round: 1 media: question: - pix/question1.png - - videos/question1.webm + - videos/big-buck-bunny_trailer.webm explanation: - - videos/question1.webm + - videos/big-buck-bunny_trailer.webm - pix/question1.png --- !Question @@ -42,4 +42,4 @@ media: - pix/facebook.jpg - pix/facebook-jail.png explanation: - - videos/faschistbook.webm + - videos/big-buck-bunny_trailer.webm diff --git a/tools/test_data/videos/big-buck-bunny_trailer.webm b/tools/test_data/videos/big-buck-bunny_trailer.webm new file mode 100644 index 0000000..6a17395 Binary files /dev/null and b/tools/test_data/videos/big-buck-bunny_trailer.webm differ diff --git a/tools/test_questions.yaml b/tools/test_questions.yaml deleted file mode 100644 index 91d865f..0000000 --- a/tools/test_questions.yaml +++ /dev/null @@ -1,43 +0,0 @@ -#--- !Question -#question: What is the question? -#answers: -# - Answer 1 -# - Answer 2 -# - Answer 3 -# - Answer 4 -#tier: 1 -#game_round: 1 -#media: -# - aaa -# - bbb - -!!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: - question: - - pix/question1.png - explanation: - - 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: - question: - - pix/facebook.jpg - - pix/facebook-jail.png - explanation: - - videos/faschistbook.webm