class CodeOnlyAnswerPicker(PostPicker): def __init__(self): super().__init__() self.cr = CodeReview() @property def url(self): return URL 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 answer.is_accepted: logging.info('answer is accepted, skip: {}'.format(answer.id)) return None if answer.score != 0: logging.info('answer has score != 0, skip: {}'.format(answer.id)) return None logging.info('fetching question {}'.format(answer.question_id)) try: question = self.cr.question(answer.question_id) except ValueError as e: logging.error('error when fetching answer: '.format(e)) return None if 'closed_date' in question.json: logging.warning('question closed, skip: {}'.format(answer.url)) return None return [INTRO_MESSAGE, answer.url]
class NarutoPicker(PostPicker): def __init__(self): super().__init__() self.cr = CodeReview() @property def url(self): return URL 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)