예제 #1
0
def follow_questions(follower_id, question_ids_per_site):                                
    ids = following_ids(follower_id.user)
    count = sum_dict(ids) + sum_dict(question_ids_per_site)
    if (count >= guru_globals.max_follow_tags):
        raise TooManyQuestions

    delete_following_ids(follower_id.user)

    for domain in question_ids_per_site:
        api = StackOverflow.Api.get_and_validate(domain)
        
        if not api:
            raise InvalidDomain(domain)
        
        question_ids = question_ids_per_site[domain]
        questions = api.questions(question_ids)
        
        valid_questions_ids = map(lambda q: q['question_id'], questions)
        valid_questions_set = set(valid_questions_ids)
        logging.debug("valid questions id %s" % (valid_questions_ids,))        
        left_question_set = set(question_ids) - valid_questions_set
        if len(left_question_set) > 0:
            raise InvalidQuestions(left_question_set)
        
        end_time = datetime.now() + timedelta(days=guru_globals.default_question_scan_lifespan_days)
        for question in questions:
            question_id = question['question_id']
            title = question['title']
            q = Question.create(question_id, end_time, domain, title)  
                
            QuestionFollower.create(q, follower_id.user)
    
        yield (domain, questions)
예제 #2
0
def follow_questions(follower_id, question_ids_per_site):
    ids = following_ids(follower_id.user)
    count = sum_dict(ids) + sum_dict(question_ids_per_site)
    if (count >= guru_globals.max_follow_tags):
        raise TooManyQuestions

    delete_following_ids(follower_id.user)

    for domain in question_ids_per_site:
        api = StackOverflow.Api.get_and_validate(domain)

        if not api:
            raise InvalidDomain(domain)

        question_ids = question_ids_per_site[domain]
        questions = api.questions(question_ids)

        valid_questions_ids = map(lambda q: q['question_id'], questions)
        valid_questions_set = set(valid_questions_ids)
        logging.debug("valid questions id %s" % (valid_questions_ids, ))
        left_question_set = set(question_ids) - valid_questions_set
        if len(left_question_set) > 0:
            raise InvalidQuestions(left_question_set)

        end_time = datetime.now() + timedelta(
            days=guru_globals.default_question_scan_lifespan_days)
        for question in questions:
            question_id = question['question_id']
            title = question['title']
            q = Question.create(question_id, end_time, domain, title)

            QuestionFollower.create(q, follower_id.user)

        yield (domain, questions)
예제 #3
0
 def testBasicPersistence(self):
   switchToTestDatabase()  
   u=User(login='******')
   u.create()
   u=u.findByLogin()
   id=u.id
   print id
   
   q=Question(asker=id,content="To be or not to be?")
   #print "before persistence: ",q
   print q.content
   question=q.create()
   deleteTestDatabase()
예제 #4
0
    def testBasicPersistence(self):
        switchToTestDatabase()
        u = User(login='******')
        u.create()
        u = u.findByLogin()
        id = u.id
        print id

        q = Question(asker=id, content="To be or not to be?")
        #print "before persistence: ",q
        print q.content
        question = q.create()
        deleteTestDatabase()