cats = ['art', 'lit', 'military', 'music', 'nonfic', 'people'] tags = { 'art': 'who made ', 'lit': 'who wrote ', 'military': 'what was ', 'music': 'who composed ', 'nonfic': 'who wrote ', 'people': 'who was ' } questions = [] cat_questions = {} for cat in cats: fn = 'blueplate/' + cat + '.xlsx' qs_raw = pd.read_excel(fn).values.tolist() cat_qs = [question(tags[cat] + q[0], q[1]) for q in qs_raw] questions.extend(cat_qs) cat_questions[cat] = cat_qs def get_random_fact(): return choice(questions) def get_random_facts(num_facts): return sample(questions, num_facts) def get_random_fact_by_cat(cat): if not cat in cat_questions: raise Exception('ERROR! Invalid Category: ' + str(cat))
def get_random_bonuses(num): if num == 0: return [] cmd = 'SELECT * FROM bonus_parts ORDER BY random() LIMIT ' + str(num) + ';' cursor.execute(cmd) res = cursor.fetchall() return [question(quest[2], quest[3]) for quest in res]
def get_random_bonus(): cursor.execute('SELECT * FROM bonus_parts ORDER BY random() LIMIT 1;') res = cursor.fetchone() return question(res[2], res[3])
def get_random_tossups(num): if num == 0: return [] cmd = 'SELECT * FROM tossups ORDER BY random() LIMIT ' + str(num) + ';' cursor.execute(cmd) res = cursor.fetchall() return [question(quest[1], quest[2]) for quest in res]
def get_random_tossup(): cursor.execute('SELECT * FROM tossups ORDER BY random() LIMIT 1;') res = cursor.fetchone() return question(res[1], res[2])