Example #1
0
 def save(self):
     if self.id is None:
         DESIRED_QUESTIONS = 20
         self.id = str(uuid4())
         all_questions = user_store.keys('question:*')
         all_questions = [int(x[9:]) for x in all_questions]
         if len(all_questions) < DESIRED_QUESTIONS:
             raise Exception("Not enough questions")
         random_questions = random.sample(all_questions, DESIRED_QUESTIONS)
         for q in random_questions:
             user_store.sadd('user_questions:' + self.id, q)
     user_store.hmset('user:'******'id': self.id,
         'name': self.name,
         'email': self.email,
         'branch': self.branch,
         'roll_no': self.roll_no,
         'score': self.score
     })
Example #2
0
from mycq import user_store
import json

questions = json.load(open("questions.json", "r"))

for q in questions:
    user_store.hmset("question:" + str(q['id']), q)