JSON input files are written now
This commit is contained in:
parent
8f045dca21
commit
5866e751fb
|
@ -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 <fb@alien8.de>"
|
||||
|
@ -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()
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 110 KiB |
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
|
@ -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
|
||||
|
|
Binary file not shown.
|
@ -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
|
Loading…
Reference in New Issue