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
|
It's just a helper to write the questions in a more human
|
||||||
readeable format assuming yaml is more human readable
|
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:
|
TODO:
|
||||||
* Add own constructor to Question() / nice to have
|
* Add own constructor to Question() / nice to have
|
||||||
* Deal with media files
|
* Use import logging for debug logging
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__author__ = "Frank Becker <fb@alien8.de>"
|
__author__ = "Frank Becker <fb@alien8.de>"
|
||||||
|
@ -191,6 +194,13 @@ def questions_per_round(questions, game_round=None):
|
||||||
"""docstring for questions_per_round"""
|
"""docstring for questions_per_round"""
|
||||||
return [q for q in questions if q.game_round == game_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():
|
def main():
|
||||||
"""docstring for main"""
|
"""docstring for main"""
|
||||||
|
|
||||||
|
@ -218,8 +228,9 @@ def main():
|
||||||
|
|
||||||
game_rounds = sorted(Question.registered_questions.keys())
|
game_rounds = sorted(Question.registered_questions.keys())
|
||||||
for r in game_rounds:
|
for r in game_rounds:
|
||||||
print json.dumps([q.as_dict for q in questions_per_round(
|
write_json_file(questions_per_round(questions, game_round=r))
|
||||||
questions, game_round=r)], indent=2)
|
if options.debug:
|
||||||
|
print "Written file for game round: {0}".format(r)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
0
tools/test_data/pix/facebook-jail.png
Normal file
0
tools/test_data/pix/facebook-jail.png
Normal file
BIN
tools/test_data/pix/facebook.jpg
Normal file
BIN
tools/test_data/pix/facebook.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 110 KiB |
BIN
tools/test_data/pix/question1.png
Normal file
BIN
tools/test_data/pix/question1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
|
@ -23,9 +23,9 @@ game_round: 1
|
||||||
media:
|
media:
|
||||||
question:
|
question:
|
||||||
- pix/question1.png
|
- pix/question1.png
|
||||||
- videos/question1.webm
|
- videos/big-buck-bunny_trailer.webm
|
||||||
explanation:
|
explanation:
|
||||||
- videos/question1.webm
|
- videos/big-buck-bunny_trailer.webm
|
||||||
- pix/question1.png
|
- pix/question1.png
|
||||||
|
|
||||||
--- !Question
|
--- !Question
|
||||||
|
@ -42,4 +42,4 @@ media:
|
||||||
- pix/facebook.jpg
|
- pix/facebook.jpg
|
||||||
- pix/facebook-jail.png
|
- pix/facebook-jail.png
|
||||||
explanation:
|
explanation:
|
||||||
- videos/faschistbook.webm
|
- videos/big-buck-bunny_trailer.webm
|
||||||
|
|
BIN
tools/test_data/videos/big-buck-bunny_trailer.webm
Normal file
BIN
tools/test_data/videos/big-buck-bunny_trailer.webm
Normal file
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
Block a user