def accept(self, post_id): """ memo: deleted questions are excluded by Stack API :param post_id: id of a question :return: messages to send, or falsy to reject """ logging.info('fetching question {}'.format(post_id)) try: question = self.cr.question(post_id) except ValueError as e: logging.error('error when fetching question: '.format(e)) return None if 'closed_date' in question.json: logging.warning('question closed, skip: {}'.format(question.url)) return None if question.score != 0: logging.warning('question has non-zero score, skip: {}'.format(question.url)) return None if question.answers: logging.warning('question has answers, skip: {}'.format(question.url)) return None if question.comments.fetch(): logging.warning('question has comments, skip: {}'.format(question.url)) return None if self.recently_awarded_tumbleweed(question.owner_id, question.creation_date): logging.warning('owner has recently received tumbleweed, skip: {}'.format(question.url)) return None return format_post(DESCRIPTION, question.title, question.url, question.tags)
def accept(self, post_id): """ memo: deleted answers are excluded by Stack API memo: deleted questions are excluded by Stack API :param post_id: id of an answer :return: messages to send, or falsy to reject """ logging.info('fetching answer {}'.format(post_id)) try: answer = self.cr.answer(post_id) except ValueError as e: logging.error('error when fetching answer: '.format(e)) return None if not answer.is_accepted: logging.warning('answer not accepted, skip: {}'.format(answer.url)) return None if answer.score != 0: logging.warning('score not zero, skip: {}'.format(answer.url)) return None question = self.cr.question(answer.question_id) if 'closed_date' in question.json: logging.warning('question closed, skip: {}'.format(answer.url)) return None if question.owner_id == answer.owner_id: logging.warning('answer owner is the same as question owner, skip: {}'.format(answer.url)) return None return format_post(DESCRIPTION, question.title, answer.url, question.tags)
def accept(self, post_id): """ memo: deleted answers are excluded by Stack API memo: deleted questions are excluded by Stack API :param post_id: id of a question :return: messages to send, or falsy to reject """ logging.info('fetching question {}'.format(post_id)) try: question = self.cr.question(post_id) except ValueError as e: logging.error('error when fetching question: '.format(e)) return None if 'closed_date' in question.json: logging.warning('question closed, skip: {}'.format(question.url)) return None score_0_exists = False for answer in question.answers: if answer.score > 0: logging.warning('answer with postitive score exists, skip: {}'.format(answer.url)) return None if answer.is_accepted: logging.warning('accepted answer exists, skip: {}'.format(answer.url)) return None if answer.score == 0: score_0_exists = True if not score_0_exists: logging.warning('no answer with 0 score, skip: {}'.format(question.url)) return None return format_post(DESCRIPTION, question.title, question.url, question.tags)