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)
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)