Пример #1
0
def get_news_list(date_str):
    dao = DailyDao(config.DB_HOST, config.DB_PORT, config.DB_USER,
                   config.DB_PASS, config.DB_NAME)
    news_list = []
    try:
        wait_for_indexed_news_list = dao.get_news_list(date_str)
        for news in wait_for_indexed_news_list:
            news_list.append(dict(news_id=news[1], title=news[2], body=news[5]))
        return news_list
    finally:
        dao.close()
Пример #2
0
def get_daily_news(date_str):
    """获取日报信息
    """
    news_list = []
    dao = DailyDao(config.DB_HOST, config.DB_PORT, config.DB_USER,
                   config.DB_PASS, config.DB_NAME)
    try:
        newses = dao.get_news_list(date_str)
        if newses:
            for news in newses:
                news_list.append(dict(share_url=news[3],
                                      image_public_url=news[8],
                                      image_source=news[7],
                                      title=news[2]))
        return news_list
    finally:
        dao.close()
Пример #3
0
def get_daily_news(date_str):
    """获取日报信息
    """
    news_list = []
    dao = DailyDao(config.DB_HOST, config.DB_PORT, config.DB_USER,
                   config.DB_PASS, config.DB_NAME)
    try:
        newses = dao.get_news_list(date_str)
        if newses:
            for news in newses:
                news_list.append(
                    dict(share_url=news[3],
                         image_public_url=news[8],
                         image_source=news[7],
                         title=news[2]))
        return news_list
    finally:
        dao.close()
Пример #4
0
def not_exists_news_ids(date_str, latest_news_ids):
    """找出所有不存在的news_ids

    :param date_str:
    :param latest_news_ids:
    :return:
    """
    dao = DailyDao(config.DB_HOST, config.DB_PORT, config.DB_USER,
                   config.DB_PASS, config.DB_NAME)
    not_exists_news_ids = []
    try:
        exists_news_ids = [str(news[1]) for news
                           in dao.get_news_list(date_str)]
        for news_id in latest_news_ids:
            if str(news_id) not in exists_news_ids:
                not_exists_news_ids.append(news_id)
    finally:
        dao.close()
    return not_exists_news_ids
Пример #5
0
def search(keywords, start, limit):
    """搜索接口

    Argumenst:
      keywords: 关键词语
      start: 开始位置
      limit: 返回个数

    Returns:
      tuple: (total_count, results)
    """
    fts_searcher = AliFTSSearcher(config.ALI_SEARCH_HOST, config.ALI_SEARCH_APP,
                                  config.ACCESS_KEY, config.ACCESS_SECRET)

    db = DailyDao(config.DB_HOST, config.DB_PORT, config.DB_USER,
                  config.DB_PASS, config.DB_NAME)
    try:
        hits = []
        results = fts_searcher.search(keywords, start=start, limit=limit)

        for hit in results:
            news = db.get_news(hit['news_id'])
            title = hit['title']
            summary = hit['content']
            hits.append(dict(
                image_public_url=news[8],
                share_url=news[3],
                date=news[4],
                title=title,
                summary=summary,
            ))

        return results.total_count, hits
    finally:
        db.close()
        fts_searcher.close()
Пример #6
0
def store_news_list(news_list):
    """将news_list保存到数据库中

    :param news_list:
    :return:
    """
    dao = DailyDao(config.DB_HOST, config.DB_PORT, config.DB_USER,
                   config.DB_PASS, config.DB_NAME)
    try:
        for news in news_list:
            dao.insert(news['public_image_url'],
                       news['date_str'],
                       news['news'])
    finally:
        dao.close()