示例#1
0
def generate_blank_bingos_challenge(lex, ch_date):
    """
    Contact blank challenges server and generate said challenges.

    """
    bingos = Questions()
    logger.debug('in generate_blank_bingos_challenge')
    for length in (7, 8):
        try:
            challs = gen_blank_challenges(length, lex.lexiconName, 2, 25, 5)
        except MacondoError:
            logger.exception(u'[event=macondoerror]')
            return bingos
        for chall in challs:
            question = Question(Alphagram(chall['q']), [])
            question.set_answers_from_word_list(chall['a'])
            bingos.append(question)
    return bingos
示例#2
0
def get_questions_by_condition(db, min_prob, max_prob, length, condition,
                               condition_type='alphagram'):
    """
    Get all questions that match the condition. Return a to_python
    representation, ready for saving into the list.

    """
    qs = Questions()

    to_filter = db.get_questions_for_probability_range(min_prob, max_prob,
                                                       length)
    for q in to_filter.questions_array():
        if condition_type == Condition.ALPHAGRAM:
            test = condition(q.alphagram.alphagram)
        elif condition_type == Condition.WORD:
            test = any(condition(word) for word in q.answers)
        if test:
            # print 'passed test', q, q['q'], q['a'][0].word
            qs.append(q)

    return qs.to_python()