def do_new_question(sender): logger("Entering do_new_question (%s)" % (sender)) user = User.objects.get(phonenumber=sender) cursor = connection.cursor() cursor.execute("select id from main_dictionary where id not in (select word_uid_id from main_submitted submitted where user_uid_id=%s) order by rand() limit 1", [user.id]) row = cursor.fetchone() logger("Selected word, uid %s" % (row)) word_id = row[0] cursor.execute("select t1.id from main_dictionary t1 where t1.id != %s order by rand() limit 3", [word_id]); choices_ids = cursor.fetchall() # return (word_id,) , random.shuffle(map(lambda x: x[0], choices_ids)+[word_id]) choices = map(lambda x: x[0], choices_ids)+[word_id] random.shuffle(choices) correct = Dictionary(id=word_id) one = Dictionary(id=choices[0]) two = Dictionary(id=choices[1]) three = Dictionary(id=choices[2]) four = Dictionary(id=choices[3]) question = Questions(user=user,correct=correct,one=one,two=two,three=three,four=four) rc = question.save() logger("question.save() rc %s" % rc) new_time = time.strftime("%Y-%m-%d %H:%M", gmtime(time.time()+ 60 * user.interval) ) pending_event = PendingEvents(user=user, time = new_time) rc = pending_event.save() logger("pending_event.save() rc %s" % rc) logger("Exiting do_new_question"); return
def do_resend(sender): logger("Entering do_resend (%s)" % (sender)) user = User.objects.get(phonenumber=sender) new_time = time.strftime("%Y-%m-%d %H:%M", gmtime(time.time() )) pending_event = PendingEvents(user=user, time = new_time) rc = pending_event.save(); logger("pending_event.save() rc %s" % rc) logger("Exiting do_resend");