Ejemplo n.º 1
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()
Ejemplo n.º 2
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()
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
def prepare_test():
    t = Test()
    questions = [
        Question(t, row[0], inverted=(row[1] == 1))
        for row in ActiveRecord.execute(TestPreparationQuery %
                                        QuestionsPerTest)
    ]
    t.save()
    return t
    def get(self):
        two_weeks_ago = datetime.now() - timedelta(
            days=guru_globals.default_question_scan_lifespan_days)
        old_questions_followers = QuestionFollower.all().filter(
            'created < ', two_weeks_ago)
        db.delete(old_questions_followers)

        old_questions = Question.all().filter('end_time < ', datetime.now())
        db.delete(old_questions)
Ejemplo n.º 7
0
    def _scan(self):
        domain_ids = {}
        for question in Question.all().order('domain'):
            domain_ids.setdefault(question.domain,
                                  []).append(str(question.question_id))

        for domain in domain_ids:
            for chunk in chunks(domain_ids[domain],
                                guru_globals.question_batch_size):
                AnswerTask.create_and_queue(domain, chunk)
                CommentTask.create_and_queue(domain, chunk)
Ejemplo n.º 8
0
    def _scan(self, domain, ids, page=1, pagesize=100):
        api = StackOverflow.Api(domain)

        total, comments = api.question_commments(ids,
                                                 pagesize=pagesize,
                                                 page=page)

        if total > page * pagesize:
            CommentTask.create_and_queue(ids, page + 1)

        logging.debug("scanning questions %s for comments on %s" % (
            ids,
            domain,
        ))
        question_ids = map(lambda id: int(id), ids)
        values = list(Question.get_by_ids_domain(domain, ids))
        questions = dict(zip(question_ids, values))
        questions_update_time = {}
        updated_questions = {}
        notify_comments = {}
        for comment in comments:
            question_id = comment['post_id']
            question = questions[question_id]
            comment_time_unix = comment['creation_date']
            comment_time = datetime.fromtimestamp(comment_time_unix)
            if not question.last_comment_time or question.last_comment_time < comment_time:
                if not question_id in questions_update_time or questions_update_time[
                        question_id] < comment_time:
                    questions_update_time[question_id] = comment_time

                if not question_id in updated_questions:
                    updated_questions[question_id] = question

                if not question in notify_comments:
                    notify_comments[question] = []

                notify_comments[question].append(comment)

        for question_id in questions_update_time:
            updated_questions[
                question_id].last_comment_time = questions_update_time[
                    question_id]

        db.put(updated_questions.values())
        self._notify_comments(domain, notify_comments)
Ejemplo n.º 9
0
    def _scan(self, domain, ids, page=1, pagesize=100):
        api = StackOverflow.Api(domain)

        total, answers = api.question_ansewrs(ids,
                                              pagesize=pagesize,
                                              page=page)

        if total > page * pagesize:
            AnswerTask.create_and_queue(ids, page + 1)

        question_ids = map(lambda question_id: int(question_id), ids)
        values = list(Question.get_by_ids_domain(domain, ids))
        questions = dict(zip(question_ids, values))
        questions_update_time = {}
        updated_questions = {}
        notify_answers = {}
        for answer in answers:
            question_id = answer['question_id']
            question = questions[question_id]
            if 'last_edit_date' in answer:
                answer_time_unix = answer['last_edit_date']
            else:
                answer_time_unix = answer['creation_date']

            answer_time = datetime.fromtimestamp(answer_time_unix)
            if not question.last_answer_time or question.last_answer_time < answer_time:
                if not question_id in questions_update_time or questions_update_time[
                        question_id] < answer_time:
                    questions_update_time[question_id] = answer_time

                if not question_id in updated_questions:
                    updated_questions[question_id] = question

                if not question in notify_answers:
                    notify_answers[question] = []

                notify_answers[question].append(answer)

        for question_id in questions_update_time:
            updated_questions[
                question_id].last_answer_time = questions_update_time[
                    question_id]

        db.put(updated_questions.values())
        self._notify_answers(api.domain, notify_answers)
Ejemplo n.º 10
0
    def create(self, text, user_id):
        id = str(uuid.uuid4())
        question = Question(id, text, user_id)
        self.data_store[id] = question

        return question