def quiz_methods(quiz_name): if request.method == 'GET': return api.get_questions(quiz_name) elif request.method == 'POST': answers = request.get_json() return api.get_grade(quiz_name, answers) else: return "The Quiz API only supports GET and POST requests"
def run(self, args_list, auth_user, key): if len(args_list) != 1: raise WrongNumberArguments('Command takes one argument.') name = args_list[0] qs = api.get_questions(self._hosts, auth_user, key) q = list(filter(lambda x: x.name == name, qs))[0] return str(q)
def run(self, args_list, auth_user, key): if len(args_list) != 0: raise WrongNumberArguments('Command takes no arguments.') qs = api.get_questions(self._hosts, auth_user, key) if len(qs) == 0: return 'There are currently no questions to answer.' s = qs[0].get_title() for q in qs[1:]: s += '\n' + q.get_title() return s
def setup(): #turn string of team names into a list teams = request.form.get("team_names").split(",") teams.pop() #initialize global variables global info global categories global questions global scores global score_rule global penalty #info is a dictionary: keys are question categories selected by user #values are lists containing true/false values where true means question has been answered already info = {} #categories is a list of question categories selected by user categories = [] #questions is a list containing each card's question, incorrect and correct answers questions = [] #scores is a dictionary: keys are team names and values are # of points earned by teams scores = {} for team in teams: scores[team] = 0 #cats: local variable storing inputted categories from HTML form cats = request.form.getlist("category") for cat in cats: info[api.get_category(int(cat))] = [False] * 5 questions.append(api.get_questions(int(cat))) categories.append(api.get_category(int(cat))) score_rule = request.form.get('score_rule') if (score_rule == "customized"): penalty = int(request.form.get('deduct')) return render_template("questions.html", correct = json.dumps(""),teams=teams, info=info, categories=json.dumps(categories), clicked=json.dumps(info),scores=scores)
from api import get_questions URL = "https://opentdb.com/api.php" question_data = get_questions(URL, amount=9, type="boolean")