示例#1
0
文件: ranker.py 项目: gogasca/news_ml
def get_and_rank_news_articles(date='latest'):
    """Get Articles in DB and assigns them a score.

    Args:
        date: (str)

    Returns:
        News information from Database.
    """
    if not date:
        raise ValueError('Invalid date')

    if date == 'latest':
        date = str(DbHelper.get_record(settings.RANKING_QUERY_DATE))
        logging.info('Using latest date. The latest date found was: %s', date)
        if not date:
            raise ValueError('Unable to extract date')

    logging.info('Using date: %s', date)
    if re.match('\d{4}-\d{1,2}-\d{2}', date):
        news = get_articles_by_date(date)
        if news:
            logging.info('Ranking started.')
            return rank_articles(news)
        else:
            raise ValueError('No news found')
    else:
        raise ValueError('Invalid date format')
示例#2
0
    def get_articles(self, date='latest'):
        """Read posts from database.

        :param date:
        :return:
        """

        # Get latest date for News inserted in Database.
        if date == 'latest':
            date = DbHelper.get_record(settings.CLUSTERING_QUERY_DATE)
            logging.info('Using latest date. The latest date found was: %s',
                         date)
        logging.info('Using date: %s', date)
        if re.match('\d{4}-\d{1,2}-\d{2}', date):
            self.articles = get_articles_by_date(date)
            logging.info('Found %d articles.' % len(self.articles))
        return self.articles