Beispiel #1
0
 def setUp(self):
     self.question = "Did the Main Character Dies?"
     self.title = "Spoil Hello World"
     self.difficulty = "Hardcore"
     self.topic_object = Topic(topic_name="Hello World")
     self.question_object = Question(topic=self.topic_object,
                                     question_text=self.question,
                                     question_title=self.title,
                                     difficulty=self.difficulty)
Beispiel #2
0
def get_question_to_create(game: Game,
                           existing_questions: List[Question]) -> Question:
    while True:
        question_pair = get_random_language_pair()
        existing_question_words = [
            question.question for question in existing_questions
        ]
        new_question_word = question_pair["english_word"]
        if new_question_word not in existing_question_words:
            answer_words = get_question_answers(question_pair)
            return Question(
                game=game,
                question=new_question_word,
                correct_answer=question_pair["russian_word"],
                answer_words=answer_words,
            )
def get_question_to_create(
    game: Game,
    pictures_topic: PicturesTopic,
    existing_questions: List[Question],
) -> Question:
    while True:
        new_question_item = get_random_topic_item(pictures_topic)
        new_question_link = static(
            get_file_path(pictures_topic, new_question_item))
        existing_question_links = [
            question.question for question in existing_questions
        ]
        if new_question_link not in existing_question_links:
            answers = get_answers(pictures_topic, new_question_item)
            return Question(
                game=game,
                question=new_question_link,
                answer_words=answers,
                correct_answer=new_question_item[0],
            )
import json
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'jeopardy.settings')

import django
django.setup()

from game.models import Question

question_file = open('jeopardy_questions.json', 'r')
data = question_file.read()

obj = json.loads(data)

l = len(Question.objects.all())
for o in range(len(obj)):
    q = Question(question_no=(l + o + 1),
                 question=obj[o]['clue'],
                 answer=obj[o]['answer'],
                 points=obj[o]['points'],
                 category=obj[o]['tag'])
    q.save()
Beispiel #5
0
#python3 dbpopulate.py filename domain category

import csv, random, sys
from game.models import Question, Choice, Category, Domain
filename = sys.argv[1]
d,res = Domain.objects.get_or_create(domain=sys.argv[2])
d.save()
cat, res = Category.objects.get_or_create(category=sys.argv[3],domain=d)
cat.save()

with open('Questions-Repo/'+filename) as f:
    questions = csv.reader(f)
    for question in questions:
        text = question[0]
        c = Choice(choice=question[1],correct=True)
        c.save()
        choice_list = [c]
        for choice in question[2:]:
            if not choice:
                break
            c = Choice(choice=choice)
            c.save()
            choice_list.append(c)

        random.shuffle(choice_list)
        q = Question(question=text,category=cat)
        q.save()
        q.choices.set(choice_list)
        q.save()