def send_new_comment_message(self, last_seen_comment_id: str, login: str, entry_id: str) -> None: try: # TODO https://github.com/krasnoludkolo/wykop-taktyk/issues/51 message = f'nowy komentarz {entry_url}/{entry_id}/#comment-{last_seen_comment_id}\nAby przestać obserowować ten wpis napisz mi wiadomość o treści: {entry_id}' self.__send_message(login, message) except ReceiverHasBlockedDMError: logger.info(f'Error during sending message to {login}')
def __update_login_observation(self, comments_count: int, entry_id: str, login_observation: LoginObservation): self.repo.add_login_to_observation(entry_id, login_observation) saved_comments_count = self.repo.get_comment_count(entry_id) logger.info( f'observation update: {entry_id} {max(saved_comments_count, comments_count)}' )
def __remove_observation_from_message(self, login, message) -> Optional[str]: entry_id = self.__take_entry_id_from_message(message) if self.repo.has_observation_with_login(entry_id, login): logger.info(f'Removing {login} from {entry_id}') self.repo.remove_login_from_observation(entry_id, login) return entry_id return None
def __save_new_observation(self, observation_candidate: ObservationCandidate): login, entry_id, comment_id, comments_count, mode = observation_candidate login_observations = {login: LoginObservation(login, comment_id, mode)} observation = Observation(login_observations, entry_id, comment_id, comments_count) self.repo.save(observation) logger.info(f'new observation: {observation}')
def process_observation(self, observation) -> NoReturn: entry_id = observation.entry_id logger.debug(f'Processing entry with id: {entry_id}') try: entry = self.api.entry(entry_id) except EntryDoesNotExistError: logger.info( f'Entry with id: {entry_id} no longer exists. Marking observation as inactive' ) self.repo.mark_as_inactive(entry_id) return entry_info = EntryInfo(entry) if observation.comments_count < entry_info.current_comments_count: logger.debug(f'New comments to entry with id: {entry_id}') logins = filter_logins_to_send_message(observation, entry_info) logger.debug(f'Logins to send message: {logins}') last_comment_id = entry_info.comments[-1].comment_id self.__send_message_to_logins_about_entity(last_comment_id, observation, logins) self.repo.set_observation_comment_count( observation.entry_id, entry_info.current_comments_count) else: logger.debug(f'No new comments to entry with id: {entry_id}')
def __send_message(self, login, message) -> None: logger.info(f'send message to: {login}. Message: {message}') self.api.message_send(login, message)