Exemplo n.º 1
0
    def __get_endpoint(self, last_update_date, pos):
        """Returns the end-point to call given a
        date (`/{pos}/recent` or `/{pos}/last`).
        Arguments:
            last_update_date -- the date of the last update
            the user has saved locally;
            pos -- flag to choose between Bot IPs POS feed and the normal
                one.
        """
        logger = logging.getLogger('__get_endpoint')

        pos_prefix = 'pos_' if pos else ''
        now = DateUtils.now()
        now_str = DateUtils.to_iso_date(now)
        if last_update_date is None:
            logger.info(self.__MESSAGES['no_last_update'])
            return self.__END_POINTS[pos_prefix + 'recent']
        else:
            update_time = self.cache_ttl
            n_available_updates = self.out_of_date_time
            outdated = DateUtils.is_outdated(now,
                                             last_update_date,
                                             update_time * 2)

            if outdated:
                logger.info(self.__MESSAGES['last_updated_at'].format(
                    last_update_date))
                return self.__END_POINTS[pos_prefix + 'recent']
            else:
                logger.info(self.__MESSAGES['last_updated_at'].format(
                    last_update_date))
                return self.__END_POINTS[pos_prefix + 'last']
Exemplo n.º 2
0
    def __get_endpoint(self, last_update_date):
        """Returns the end-point to call given a
        date (`/online`, `/recent` or `/last`).
        Arguments:
            last_update_date -- the date of the last update
            the user has saved locally.
        """
        logger = logging.getLogger('__get_endpoint')

        now = DateUtils.now()
        now_str = DateUtils.to_iso_date(now)
        if last_update_date is None:
            logger.info(self.__MESSAGES['no_last_update'])
            return self.__END_POINTS['online']
        else:
            update_time = self.cache_ttl
            n_available_updates = self.out_of_date_time
            partially_outdated = DateUtils.is_outdated(now,
                                                       last_update_date,
                                                       update_time * 2)
            fully_outdated = DateUtils.is_outdated(now,
                                                   last_update_date,
                                                   update_time *
                                                   n_available_updates)

            if fully_outdated:
                logger.info(self.__MESSAGES['outdated_db'])
                return self.__END_POINTS['online']
            elif partially_outdated:
                logger.info(self.__MESSAGES['last_updated_at'].format(
                    last_update_date))
                return self.__END_POINTS['recent']
            else:
                logger.info(self.__MESSAGES['last_updated_at'].format(
                    last_update_date))
                return self.__END_POINTS['last']